Closed aniketshewale85 closed 2 years ago
Hey @aniketshewale85 ,
Can you share the logs, I think there is some dependency which you missed adding into build.gradle due to which InMobi SDK is not initialized.
This is my Logs I am using admob consent SDK to determine whether user is located in EU or not. And using Shared Preferences to save Inmobi SDK initialized successfully or not. If successful, requesting banner and interstitial Ad in another activity
Caused by com.inmobi.ads.exceptions.SdkNotInitializedException
Please initialize the SDK before creating InMobiBanner ad
com.inmobi.ads.InMobiBanner.
Can you share the full logs by enabling InMobi DEBUG logs InMobiSdk.setLogLevel(LogLevel.DEBUG);
and after then you callInMobiSdk.init(..)
you should get something like InMobi SDK initialized with account id:
in your logs.
If you're not getting this then there is something wrong with the integration, and you should get the error log which should explain why sdk initialization failed.
Which InMobi SDK version you're using?
In My device it is working fine I received these crash events Firebase Crashilytics
@aniketshewale85 Are you using the same shared preferences across the sessions to determine whether InMobi SDK is initialized or not?
No, I reset shared pref at app launch and then initialize Inmobi SDK
Can you share some code snippets on how you're initializing the InMobi SDK and saving/clear part of preferences. Or some sample app would be great which does the same thing as your app is doing.
This is on App Launcher Activity SharedPreferences preferences1 = getSharedPreferences("INMOBI_INIT_PREF", MODE_PRIVATE); SharedPreferences.Editor editor = preferences1.edit(); editor.putBoolean("SUCCESS", false); editor.apply();
Following is in Main Activity
private void getConsentStatus() {
ConsentInformation consentInformation = ConsentInformation.getInstance(this);
String[] publisherIds = {"Admob Publisher ID"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
if (ConsentInformation.getInstance(getBaseContext()).isRequestLocationInEeaOrUnknown()) {
switch (consentStatus) {
case UNKNOWN:
List<AdProvider> adProviders =
ConsentInformation.getInstance(getApplicationContext()).getAdProviders();
displayConsentForm();
break;
case PERSONALIZED:
initializeAds();
inMobiConsent(true);
break;
case NON_PERSONALIZED:
initializeAds();
inMobiConsent(false);
break;
}
} else {
// Log.d(TAG, "Not in EU, displaying normal ads");
initializeAds(); //Admob
inMobiConsent(true);
}
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
initializeAds(); // Admob
}
});
}
private void inMobiConsent(boolean consentAvailable) {
consentObject = new JSONObject();
try {
// Provide correct consent value to sdk which is obtained by User
consentObject.put(InMobiSdk.IM_GDPR_CONSENT_AVAILABLE, consentAvailable);
} catch (JSONException e) {
e.printStackTrace();
}
InMobiSdk.init(this, "3ae07cff36a548b89f351275b13f8515", consentObject, new SdkInitializationListener() {
@Override
public void onInitializationComplete(@Nullable Error error) {
if (null != error) {
Log.e("Inmobi", "InMobi Init failed -" + error.getMessage());
} else {
Log.d("Inmobi", "InMobi Init Successful");
SharedPreferences preferences = getSharedPreferences("INMOBI_INIT_PREF", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("SUCCESS", true);
editor.apply();
}
}
});
}
@aniketshewale85
Looks like it is happening due to onFailedToUpdateConsentInfo
. You are not initializing InMobi if the consent update fails.
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
initializeAds(); // Admob
}
I have added in App. I forgot to copy here
@Override public void onFailedToUpdateConsentInfo(String errorDescription) { // User's consent status failed to update. initializeAds(); // Admob inMobiConsent(true); }
@aniketshewale85 Closing the issue as the issue was raised 2 years ago. Please re-open the issue if the issue persists.
I have created banner Ad programmatically. But it is crashing on some of the devices with error SdkNotInitializedException. I have initialized SDK on Main Activity and creating a banner on the second activity.