Cordova 需要在phonegap应用程序中添加admob的帮助吗

Cordova 需要在phonegap应用程序中添加admob的帮助吗,cordova,admob,Cordova,Admob,我的基于web的应用程序使用html和css。我使用phone gap进行构建,效果很好。当我尝试将admob集成到我的应用程序中时,它显示清单文件中缺少AdActivity。我已搜索,但未找到任何答案。请帮助 <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="20" /> <supports-screens android:largeScreens="true" android:normalScree

我的基于web的应用程序使用html和css。我使用phone gap进行构建,效果很好。当我尝试将admob集成到我的应用程序中时,它显示清单文件中缺少AdActivity。我已搜索,但未找到任何答案。请帮助

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
这是我的mainactivity.java文件:

public class MainActivity extends DroidGap {
private Handler mHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");

mHandler.postDelayed(new Runnable() {
public void run() {
doAdmob();
}
}, 1000);
}
private void doAdmob() {   
// Create the adView
AdView adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-000000000000000000000000");
adView.setAdSize(AdSize.BANNER);
// Lookup your LinearLayout - get the super.root
LinearLayout layout = super.root;
// Add the adView to it
layout.addView(adView);
// This centers the ads in landscape mode.        
layout.setHorizontalGravity(android.view.Gravity.CENTER_HORIZONTAL); 
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}  
}    
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
这是我的android清单文件:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>

请帮助……….

在phonegap中,您可以尝试在每个特定平台上构建应用程序,然后通过修改代码集成admob,这似乎就是您正在尝试的。您必须为您想要支持的每个平台执行此操作,并且还必须为每个平台编写本机代码。我建议您使用一个插件,您已经完成了本机和清单集成

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
如果您想修改本机代码,可以了解如何在android和ios中集成admob

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
如果您决定使用插件,我建议您使用我正在维护的插件:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
它很容易集成:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
cordova plugin add com.admob.google
或者,如果要使用phonegap cli:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
phonegap local plugin add https://github.com/appfeel/admob-google-cordova.git
要使用它,在javascript中:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
  document.removeEventListener('deviceready', onDeviceReady, false);

  // Set AdMobAds options:
  admob.setOptions({
    publisherId:          "ca-app-pub-8440343014846849/3119840614",
    interstitialAdId:     "ca-app-pub-8440343014846849/4596573817"
  });

  // Start showing banners (atomatic when autoShowBanner is set to true)
  admob.createBannerView();

  // Request interstitial (will present automatically when autoShowInterstitial is set to true)
  admob.requestIntertitial();
}
将代码替换为您的发布者id,希望对您有所帮助

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
编辑

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
最简单、最快的方法是从命令行使用cordova插件add com.admob.google。无论如何,我在这里留下了在Eclipse中添加支持的说明:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>
从或通过命令行下载插件:git clonehttps://github.com/appfeel/admob-google-cordova.git 解压缩加载的插件 将src/android/*.java复制到您的项目文件夹/platforms/android/src/com/appfeel/cordova/admob中/ 将src/android/res/values/admob.xml复制到您的项目文件夹/platforms/android/res/values/android.xml中 打开清单文件并在标记下添加以下内容: 代码:

<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="20" />

<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>

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


<application 
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
</activity>
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        />


</application>

你检查过了吗?如果你正在使用cordova cli,请使用Hi-miquel谢谢你的回答。我是android开发新手,我不知道如何在eclipse项目中添加phonegap插件。你能帮我排序吗?@ZaffarKhan我用说明编辑了回复。请让我知道它是否适合你