Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Google play services ads and AndroidManifest.xml

$
0
0

Hi all!

I have managed to get the google play services lib included with your help, but when I run my app with the adview code, it crashes on startup. "Unfortunately, app has stopped." I think there is something missing in my AndroidManifest.xml file, but I do not know what it is and can't seem to find applicable posts online.

My AndroidManifest.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http:// schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
  <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25"/>
  <application android:debuggable="true" android:icon="@drawable/icon" android:label="">
    <activity android:name=".MainActivity">android:theme="@android:style/Theme.NoTitleBar"&gt;<intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.android.gms.ads.AdActivity"/>
    <meta-data android:name="com.google.android.gms.version" android:value="8115000"/>
  </application>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
  <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

and the code to load ads is

@ Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   Window window = getActivity().getWindow();
   RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
   RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
   // Displays Ads at the bottom of your sketch, use Gravity.TOP to display them at the top
   adsLayout.setGravity(Gravity.BOTTOM);
   AdView adView = new AdView(this.getActivity());
   adView.setAdSize(AdSize.BANNER);
   adView.setAdUnitId("adunitid");
   adsLayout.addView(adView);
    AdRequest newAdReq = new AdRequest.Builder()

    .build();

    adView.loadAd(newAdReq);
    window.addContentView(adsLayout,lp2);
}

If I comment out the line adView.loadAd(newAdReq); the app works just fine


Viewing all articles
Browse latest Browse all 941

Trending Articles