Added Admob and now getting spammed with AudioManager logs

223

As someone upvoted my question, i am putting my solution here that i have found on my own. As i said on OCT 8th, the reason is setState() so the solution is simple. I used Navigator.push... or Navigator.pushReplacement... instead of all setState() functions in my app and the error fixed. But this was pretty hard in somewhere because i needed to define new final required parametres of the class to fresh the page rightly or define some other parametres in İnherited Widget Class to use them how i want after freshing the page. So the problem solved. I found out there are some reasons like provider but i dont have enough time to learn how to use it so choose this way that i have known. If somebody explain any other solution it will be better because i dont feel ok with this solution. There must be better or more stable fix.

Share:
223
kalfalarin_omer
Author by

kalfalarin_omer

Updated on January 01, 2023

Comments

  • kalfalarin_omer
    kalfalarin_omer over 1 year

    I added admob banner and interstitial ads to my Flutter app. It looks like its working, but i am getting spammed with these logs:

    Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
    I/Ads (15325): Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("0C008B27375A350F4FEE8604765FC4E4")) to get test ads on this device.
    I/DynamiteModule(15325): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:212910700
    I/DynamiteModule(15325): Selected remote version of com.google.android.gms.ads.dynamite, version >= 212910700
    I/DynamiteModule(15325): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:212910700
    I/DynamiteModule(15325): Selected remote version of com.google.android.gms.ads.dynamite, version >= 212910700
    V/AudioManager(15325): getMode...
    V/AudioManager(15325): isMusicActive...
    V/AudioManager(15325): isSpeakerphoneOn: false
    V/AudioManager(15325): getStreamVolume streamType: 3 volume: 15
    V/AudioManager(15325): getStreamVolume streamType: 2 volume: 7
    

    as you can see here, app listening volume level, music and speaker activity and this is happening again and again and again. this log comes continuously. i did tried my app's apk in release mode on different phones and got same result. it crashed again.

    Here is my Admob Class Codes:

    import 'package:google_mobile_ads/google_mobile_ads.dart';
    
    class Reklam {
      static String get bannerUnit => "ca-app-pub-3940256099942544/6300978111";
    
      InterstitialAd _interstitialAd;
      int num_of_attempt_load = 0;
    
      static initialization() {
        if (MobileAds.instance == null) {
          MobileAds.instance.initialize();
        }
      }
    
    
      static BannerAd getBannerAd() {
        final BannerAd myBanner = BannerAd(
          adUnitId: 'ca-app-pub-MyAppBannerUnitId',
          size: AdSize.banner,
          request: AdRequest(),
          listener: BannerAdListener(
              onAdLoaded: (Ad ad) {
                print("Reklam yülendi");
              },
              onAdFailedToLoad: (Ad ad, LoadAdError error) {
                print("Reklam yüklenemedi.");
                ad.dispose();
              },
              onAdOpened: (Ad ad) {
                print("Reklam açıldı");
              }
          ),
        );
    
        return myBanner;
      }
    
    
      void createInterad() {
        InterstitialAd.load(
          adUnitId: 'ca-app-pub-MyAppInterstitialUnitId',
          request: AdRequest(),
          adLoadCallback: InterstitialAdLoadCallback(
              onAdLoaded: (InterstitialAd ad) {
                _interstitialAd = ad;
                num_of_attempt_load = 0;
              },
              onAdFailedToLoad: (LoadAdError error) {
                num_of_attempt_load + 1;
                _interstitialAd = null;
    
                if (num_of_attempt_load <= 2) {
                  createInterad();
                }
              }),
        );
      }
    
      void showInterad() {
        if (_interstitialAd == null) {
          return;
        }
    
        _interstitialAd.fullScreenContentCallback = FullScreenContentCallback(
    
            onAdShowedFullScreenContent: (InterstitialAd ad) {
              print("ad onAdshowedFullscreen");
            },
            onAdDismissedFullScreenContent: (InterstitialAd ad) {
              print("ad Disposed");
              ad.dispose();
            },
            onAdFailedToShowFullScreenContent: (InterstitialAd ad,
                AdError aderror) {
              print('$ad OnAdFailed $aderror');
              ad.dispose();
              createInterad();
            }
        );
    
        _interstitialAd.show();
    
        _interstitialAd = null;
      }
    }
    

    and here ise banner and interstitial ads integration code blocks to a page:

    ...
    class SinavlarKisilerPageState extends State<SinavlarKisilerPage> {
    ...
     Reklam _reklam = new Reklam();         //Admob Class' definiton as _reklam
     @override
     Widget build(BuildContext context) {
    
      return Scaffold(
       appbar:...,
       body: ListView(
       ...
         IconButton(
           onPressed: () {
             _reklam.createInterad();        //Interstitial Ads creats
          }),
    
       ...
          FloatingActionButton.extended(
           onPressed: () async {
            _reklam.showInterad();          //Interstitial Ads shows
         }),
       ...
        ),
      bottomNavigationBar: Container( height: 50, child: AdWidget(ad: 
       Reklam.getBannerAd()..load(), key: UniqueKey(),),),    //Banner Ads integration
      );
     }
    }
    

    Here is my android\build.gradle:

    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.6.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.8'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    

    Here is my android\app\build.gradle:

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)
        }
    }
    
    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }
    
    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
    if (flutterVersionCode == null) {
        flutterVersionCode = '1'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    android {
        compileSdkVersion 30
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.sinavci"
            minSdkVersion 19
            targetSdkVersion 30
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            multiDexEnabled true
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation platform('com.google.firebase:firebase-bom:28.2.0')
        implementation 'com.google.firebase:firebase-analytics'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.google.android.gms:play-services-ads:20.4.0'
    }
    
    

    And at last AndroidManifest:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.MyApp">
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    
       <application
            android:label="MyApp"
            android:icon="@mipmap/ic_launcher">
            <activity
                android:name=".MainActivity"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize">
    
                <meta-data
                  android:name="io.flutter.embedding.android.NormalTheme"
                  android:resource="@style/NormalTheme"
                  />
    
                <meta-data
                  android:name="io.flutter.embedding.android.SplashScreenDrawable"
                  android:resource="@drawable/launch_background"
                  />
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            
            <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
           <meta-data
               android:name="com.google.android.gms.ads.APPLICATION_ID"
               android:value="ca-app-pub-MyAppsAdmobId"/>
        </application>
    </manifest>
    

    This is the last step before publish. please help!!

    Oct 8th UPDATE:

    I did found some reasons for my errors. First of all sounds activities including volume level, music plays or speakerOn always been listening by Admob to eleminates soundfull video ads if phone muted. So thats normal. As my banner ads Loading fails continuously, admob sends request for every single fail as coded in my Admob Class so i am getting that log messages again and again and again like a spam message.

    The reason of my app's crashing is completely setState() method. As setState() freshes the page and sets the new state, admob sends a new requests and new page isnt coming after that. I coudnt find it's solution because i have to use setState() and the page needs to be refresh up to new state. How can i fix this problem? Please help.

    • kalfalarin_omer
      kalfalarin_omer over 2 years
      is there nobody here can know the solution or has an idea about this?