Posts tagged with android

having function to get AdvertisingIdClient.Info

private static AdvertisingIdClient.Info getAdsClientInfo(@NonNull final Context context) throws GooglePlayServicesNotAvailableException, IOException, GooglePlayServicesRepairableException {     int isGPAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);     if (isGPAvailable == ConnectionResult.SUCCESS) {         return AdvertisingIdClient.getAdvertisingIdInfo(context);     }     return null; } 

it uses AdvertisingIdClient.getAdvertisingIdInfo(context)

there are three libs in https://developers.google.com/android/guides/setup

Google Mobile Ads   com.google.android.gms:play-services-ads:20.1.0 Android Advertising ID (AAID)   com.google.android.gms:play-services-ads-identifier:17.0.0 Lightweight version of Google Mobile Ads com.google.android.gms:play-services-ads-lite:20.1.0 

what are the difference among these, and which one is safe to use for the purpose?

I've been struggling to integrate google ads in the flutter app. It keeps crashing.

Installed version: google_mobile_ads: ^0.12.1+1

I've updated the manifest too with the ads meta-data

<meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="<AD-CODE>" /> 

Whenever I try to debug the code on the emulator. I get these errors in the console:

Launching lib/main.dart on sdk gphone x86 arm in debug mode... ✓ Built build/app/outputs/flutter-apk/app-debug.apk. E/AndroidRuntime(23372): FATAL EXCEPTION: main E/AndroidRuntime(23372): Process: com.example.kavya_digest, PID: 23372 E/AndroidRuntime(23372): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: E/AndroidRuntime(23372): E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): * Invalid application ID. Follow instructions here:                          * E/AndroidRuntime(23372): * https://googlemobileadssdk.page.link/admob-android-update-manifest         * E/AndroidRuntime(23372): * to find your app ID.                                                       * E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): E/AndroidRuntime(23372): E/AndroidRuntime(23372):    at android.app.ActivityThread.installProvider(ActivityThread.java:7135) E/AndroidRuntime(23372):    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6675) E/AndroidRuntime(23372):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6592) E/AndroidRuntime(23372):    at android.app.ActivityThread.access$1300(ActivityThread.java:233) E/AndroidRuntime(23372):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896) E/AndroidRuntime(23372):    at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(23372):    at android.os.Looper.loop(Looper.java:223) E/AndroidRuntime(23372):    at android.app.ActivityThread.main(ActivityThread.java:7523) E/AndroidRuntime(23372):    at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(23372):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/AndroidRuntime(23372):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) E/AndroidRuntime(23372): Caused by: java.lang.IllegalStateException: E/AndroidRuntime(23372): E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): * Invalid application ID. Follow instructions here:                          * E/AndroidRuntime(23372): * https://googlemobileadssdk.page.link/admob-android-update-manifest         * E/AndroidRuntime(23372): * to find your app ID.                                                       * E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): E/AndroidRuntime(23372): E/AndroidRuntime(23372):    at com.google.android.gms.internal.ads.zzzt.attachInfo(com.google.android.gms:play-services-ads-lite@@19.7.0:24) E/AndroidRuntime(23372):    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@19.7.0:3) E/AndroidRuntime(23372):    at android.app.ActivityThread.installProvider(ActivityThread.java:7130) E/AndroidRuntime(23372):    ... 10 more Exited 

Although I have implemented com.google.android.gms.ads:20.0.0 in my project, still I am not able to use interstitialAd.setAdUnitId(), loadAd.
Here is what I have:

import androidx.multidex.BuildConfig; import com.google.android.gms.ads.Adlistener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.IntersitialAd; import com.google.android.gms.ads.intersitital.IntersisitalAd; 

Here is where I'm trying to use the method:

public void interstitalLoadAd(Context context){     mInterstitialAd = new InterstitialAd(context);     mInterstitialAd.setAdUnitId(BuildConfig.DEBUG ?         TEST_INTERSTITIAL_AD_UNIT_ID :         INTERSTITIAL_AD_UNIT_ID);     mInterstitialAd.loadAd(new AdRequest.Builder().build());     mInterstitialAd.setAdListener(this); } public void showAd(){     if (mInterstitialAd.isLoaded()){         mInterstitialAd.show();  } 

Recently my application started spamming logs with the following set of messages

W/ColorUtils: expected specified color aspects (0:0:0:0) D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.max-count.values D/ReflectedParamUpdater: extent() != 1 for single value type: output.subscribed-indices.values D/ReflectedParamUpdater: extent() != 1 for single value type: input.buffers.allocator-ids.values D/ReflectedParamUpdater: extent() != 1 for single value type: output.buffers.allocator-ids.values D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.allocator-ids.values D/ReflectedParamUpdater: extent() != 1 for single value type: output.buffers.pool-ids.values D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.pool-ids.values 

I can't see the "expected specified color aspects" in the sources my IDE has downloaded or by Googling and I have struggled to identify what triggers this, since the log is quickly overwhelmed by these messages

The only reference I found which could be related is this question but I do not use exoplayer. The only thing which may be using videos is the Google Ads SDK.

Does anyone know what the root cause is for this spam? If it's in ads, is there a way to disable it?

I have a singleton class for loading and displaying ads

object AdmobProvider {     var countLoadAds = 0     lateinit var mInterstitialAd: InterstitialAd     private val adRequest = AdRequest.Builder().build()     fun init(activity: Activity) {         MobileAds.initialize(activity)         initInterstitial(activity)     }     private fun initInterstitial(context: Activity) {         mInterstitialAd = InterstitialAd(context)         if (!SubscriptionProvider.hasSubscription()) {             mInterstitialAd.adUnitId = context.getString(R.string.interstitial_video)             mInterstitialAd.loadAd(adRequest)             mInterstitialAd.adListener = object : AdListener() {                 override fun onAdClosed() {                     super.onAdClosed()                     Log.i("AdmobProvider", "onAdClosed: ")                 }                 override fun onAdFailedToLoad(p0: Int) {                     super.onAdFailedToLoad(p0)                     countLoadAds++                     Log.i("AdmobProvider", "onAdFailedToLoad: $countLoadAds")                     if (countLoadAds <= 3) {                         initInterstitial(context)                     } else {                         callback?.Failed(true)                     }                 }                 override fun onAdOpened() {                     super.onAdOpened()                     Log.i("AdmobProvider", "onAdOpened: ")                 }                 override fun onAdLoaded() {                     super.onAdLoaded()                     Log.i("AdmobProvider", "onAdLoaded: ")                     if (mInterstitialAd.isLoaded) {                         callback?.Success(true)                     }                 }             }         }     }     fun showInterstitial() {         if (mInterstitialAd.isLoaded) {             mInterstitialAd.show()         }     } } 

I load ads via

ActivityA in onCreate()

AdmobProvider.init(this) override fun Success(state: Boolean) {         Handler().postDelayed({             val intent = Intent(this@ActivityA, ActivityB::class.java)             intent.putExtra("ActivityB", 1)             startActivity(intent)             finish()         }, 200)     } 

and show in ActivityB in onCreate()

if (intent.getIntExtra("ActivityB", 0) == 1) {     AdmobProvider.showInterstitial() } 

While I tested it on the phone and emulators everything was fine, but from users, a crash began to arrive in the ActivityB, mainly on Android 8+

java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: d.m: lateinit property mInterstitialAd has not been initialized     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3455)     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3598)     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2164)     at android.os.Handler.dispatchMessage(Handler.java:107)     at android.os.Looper.loop(Looper.java:241)     at android.app.ActivityThread.main(ActivityThread.java:7582)     at java.lang.reflect.Method.invoke(Native Method)     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) Caused by: d.m: lateinit property mInterstitialAd has not been initialized     at .b.i(Unknown Source)     at .MainActivity.onCreate(Unknown Source)     at android.app.Activity.performCreate(Activity.java:7822)     at android.app.Activity.performCreate(Activity.java:7811)     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1328)     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430) 

I understand what the error is, but I can't figure out how to fix it correctly, because if I initialize an advertisement in the second activity, I will need to load it there, but it doesn't suit me. According to statistics, 88% of cases crash in background. Please tell me how to fix it correctly?