[英]Checking internet connectivity in Android without ACCESS_NETWORK_STATE permission
[英]ERROR: “You must have INTERNET and ACCESS_NETWORK_STATE permission” with AdMob
如標題所示,即使我很確定自己在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"/>
我有同樣的問題。 但是我在清單中寫了這樣的內容,它對我有用。 我認為是某種錯誤。
希望能幫助到你!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.