错误:使用 AdMob "You must have INTERNET and ACCESS_NETWORK_STATE permission"



正如标题所述,尽管我很有信心在Android清单中得到了正确的代码,但我还是收到了那个特定的错误。我已经检查了常见的错误,比如不小心键入了"users"而不是"uses",并确保我使用了单数的"permission"。尽管我尽了最大的努力,我还是犯了这个错误。我希望你们中的一个人能指出我遗漏的东西。

以下是Android Manifest 的相关部分

<activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

这是我应该显示测试广告的整个布局。相关视图位于最底部附近。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".HomeActivity" >
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"
    android:layout_weight=".5"
    tools:context=".HomeActivity">
    <!-- Space reserved for buttons at top of screen -->
</LinearLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"
    android:layout_weight="1"
    tools:context=".HomeActivity">
    <Button
        android:id="@+id/btnAddRevenue"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_alignParentLeft="true"
        android:text="@string/btnAddRevenue_Text" />
    <Button
        android:id="@+id/btnAddExpense"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_alignParentRight="true"
        android:text="@string/btnAddExpense_Text" />
</LinearLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"
    android:layout_weight="5"
    tools:context=".HomeActivity">
    <ListView
        android:layout_height="fill_parent"
        android:layout_width="fill_parent" />
    <!-- <TextView
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:text="@string/fillerText" /> -->
</LinearLayout>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:layout_weight=".5"
        tools:context=".HomeActivity">
    <!-- Space reserved for ads -->
    <com.google.ads.AdView
        android:id="@+id/adHome_bottomBanner"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        ads:adUnitId="@string/adId_bottomBanner"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
        ads:loadAdOnCreate="true" />
</LinearLayout>

我认为这是因为您在<application>中添加了权限。你应该把它写在<manifest>标签里面。

这是示例代码。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.stackdemo"
  android:versionCode="1"
  android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.stackdemo.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  </application>
</manifest>

试试这个::

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

我也有同样的问题。但我在manifest中写过这样的东西,它对我很有效。我想是某种bug。

希望它有帮助!!

最新更新