[英]Android: how to install a downloaded application from our app similar to a playstore
[英]how to Put add in our android application
我已經為admob創建了一個應用程序,但是我收到了一個錯誤。 我找到了谷歌的一個例子,我已經嘗試過,但是當我啟動應用程序時出現問題。
我正在使用Android 2.2 API 8.我能夠啟動應用程序,但此塊導致錯誤。
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
如果我改成這個
android:configChanges="keyboard|keyboardHidden"
然后我就可以啟動應用程序,但是我們的添加字段會出現錯誤。
you must have adactivity declare in Android Manfiest.xml with config change
由於這個原因,我無法在我們的應用程序中顯示谷歌添加。
請幫我解決這個問題。
我想你只需要遵循這個教程。
特別是你的問題應該是這樣的:
適用於Android的Google AdMob Ads SDK需要Android 1.5或更高版本。 確保您擁有Android SDK的最新副本,並且您正在編譯至少Android v3.2(將default.properties中的目標設置為android-13)。
這意味着minSDK可以降至1.5但你必須至少在3.2上編譯。
來自AdMob文檔
您需要將整個活動標記添加到AndroidManifest.xml
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
請參閱https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals
- AdActivity.java
package com.android.ads;
import android.app.Activity;
import android.os.Bundle;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class AdsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AdView adview = (AdView) findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
}
}
- main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.android.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="Your adunit ID"
android:layout_alignParentBottom="true"/>
</LinearLayout>
Remember Put GoogleMapAdmobSdk.jar after creating libs folder for Configure build path
Create the attrs.xml in the Values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="adSize">
<enum name="BANNER" value="1"/>
<enum name="IAB_MRECT" value="2"/>
<enum name="IAB_BANNER" value="3"/>
<enum name="IAB_LEADERBOARD" value="4"/>
</attr>
<attr name="adUnitId" format="string"/>
</declare-styleable>
</resources>
- AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.ads"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AdsActivity"
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.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
</manifest>
Your work is done buddy............
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.