我正在创建一个应用。一旦我尝试进入包含
的活动,它就会关闭<com.google.android.gms.ads.adview
.......
/>
我已经从sdk管理器安装了google play服务,并将google play services.jar文件添加到我的Build Path中。注意。我使用Eclipse而不是android Studio。
我的Manifest.xml。我已经声明了INTERNET权限标记: -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.additiontables"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Addition_Tables"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".About_Me"
android:label="@string/title_activity_about__me" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="6111000" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
这是我的Activity.xml文件: - 我不确定是否必须使用com.google.android.gms.ads.AdView或只是com.google.ads.AdView.-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.additiontables.About_Me" >
<com.google.android.gms.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
googleads:adSize="BANNER"
googleads:adUnitId="(My Id)" />
我很沮丧。:(
请帮助。
提前致谢:)
请注意。我在Refrenced库中有googleplayservices.jar。
答案 0 :(得分:3)
请勿对Google Play服务版本号进行硬编码。使用@integer/google_play_services_version
或者它会在错误的版本上抛出IllegalStateException
。
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
有关详细信息,请参阅Setting Up Google Play Services
。
答案 1 :(得分:1)
在您的Activity类中使用
AdView adView = (AdView) this.findViewById(R.id.ad);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
答案 2 :(得分:0)
如果您的应用因最新的admob而崩溃,您可以使用替代方法
TableRow TR = (TableRow) findViewById(R.id.TR);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(getString("your admob id here"));
AdRequest adRequest = new AdRequest.Builder().build();
TR.addView(adView);
adView.loadAd(adRequest);
xml代码
<TableRow
android:id="@+id/TR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
清单文件
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="5089000" />
答案 3 :(得分:0)
private AdView adView;
RelativeLayout view_for_ads; // take a relative layout in your layout at the bottom of screen
在oncreate中adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("your id");
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
view_for_ads = (RelativeLayout) findViewById(R.id.view_for_ads);
view_for_ads.setVisibility(View.VISIBLE);
view_for_ads.addView(adView);
adView.loadAd(adRequestBuilder.build());
xml 中的<RelativeLayout
android:id="@+id/view_for_ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
</RelativeLayout>
清单 <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="portrait" />
右击 - &gt;导入 - &GT;现有代码 - &gt; SDK \演员\谷歌\ google_play_services 还可以通过选中复选框
在工作区中添加GP服务