我想問一下關於android AdMob的廣告。我創建並完成了Android應用程序,然後添加了Admob廣告。從那以後,廣告只在仿真器上顯示,但從未在我的手機(HTC渴望)屏幕上顯示。這怎麼可能以及如何解決它?AdMob廣告只出現在模擬器中
代碼:從清單代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="some text"
android:textColor="#FF0000"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:minLines="2"
android:text="some text 2"
android:textColor="#FF0000"
android:textStyle="italic" />
<EditText
android:id="@+id/someId1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint1"
android:inputType="number|numberDecimal|numberSigned" />
<EditText
android:id="@+id/someId2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint2"
android:inputType="number|numberDecimal|numberSigned" />
<EditText
android:id="@+id/someId3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint3"
android:inputType="number|numberDecimal|numberSigned" />
<Button
android:id="@+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button text" />
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint"
android:textColor="#FF0000"
android:textSize="20sp"
android:textStyle="bold" />
<com.google.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" />
</LinearLayout>
部分:
這是java代碼:
package some.some.some;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
Button button;
TextView tv1, tv2, tv3;
double a, b, c, d, e, f, g, h, i, j, l ,m ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv1.setText("");
tv2.setText("");
tv3.setText("");
}
});
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.info:
Intent i = new Intent("some.....");
startActivity(i);
break;
case R.id.preferences:
Intent p = new Intent("some.......");
startActivity(p);
break;
case R.id.exit:
finish();
break;
}
return false;
}
}
附:我的手機是HTC渴望的; Android版本2.3.5; 模擬器我使用的是4.2.2
05-31 18:31:33.974: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:33.974: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:33.994: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:34.004: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:34.004: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:34.004: I/HtcTextSelection(30023): (sendOnTextChanged) stopTextSelectionMode
05-31 18:31:34.294: D/Database(30023): dbopen(): path = /data/data/com.quad.equa/databases/webview.db, flag = 6, file size = 15360
05-31 18:31:34.324: D/Database(30023): dbopen(): path = /data/data/com.quad.equa/databases/webview.db, mode: wal, disk free size: 700 M, handle: 0x376840
05-31 18:31:34.364: D/Database(30023): dbopen(): path = /data/data/com.quad.equa/databases/webviewCache.db, flag = 6, file size = 6144
05-31 18:31:34.374: I/Database(30023): sqlite returned: error code = 0, msg = Recovered 6 frames from WAL file /data/data/com.quad.equa/databases/webviewCache.db-wal
05-31 18:31:34.374: D/Database(30023): dbopen(): path = /data/data/com.quad.equa/databases/webviewCache.db, mode: wal, disk free size: 700 M, handle: 0x3866f0
05-31 18:31:34.394: D/skia(30023): htcFlashPlugin::htcFlashPlugin
05-31 18:31:34.404: D/qct(30023): [RequestQueue.ActivePool.ActivePool] >> Enable Shutdown = true
05-31 18:31:34.404: D/qct(30023): [IdleCache.IdleCache] >> IDLE_CACHE_MAX = 40
05-31 18:31:34.524: D/qct(30023): [WebView.WebView] >> Enable Shutdown = true
05-31 18:31:34.524: D/skia(30023): htcFlashPlugin::htcFlashPlugin
05-31 18:31:34.534: D/qct(30023): [WebView.WebView] >> Enable Shutdown = true
05-31 18:31:34.754: D/dalvikvm(30023): GC_CONCURRENT freed 235K, 42% free 3319K/5639K, external 0K/0K, paused 11ms+12ms
05-31 18:31:34.854: D/skia(30023): htcFlashPlugin::htcFlashPlugin
05-31 18:31:34.854: E/ActivityThread(30023): Failed to find provider info for com.google.plus.platform
05-31 18:31:34.864: D/qct(30023): [WebView.WebView] >> Enable Shutdown = true
05-31 18:31:34.864: W/Ads(30023): loadAd called while the ad is already loading, so aborting.
05-31 18:31:34.874: D/ATRecorder(30023): com.htc.autotest.dlib.RecordEngine in loader [email protected]
05-31 18:31:34.874: D/WindowManagerImpl(30023): addView, new view, mViews[0]: [email protected]
05-31 18:31:34.884: I/Ads(30023): To get test ads on this device, call adRequest.addTestDevice("9B33F819BBF6446C23116F898BCD7877");
05-31 18:31:34.974: I/HtcTextSelection(30023): (onFocusChanged) focused =true
05-31 18:31:34.984: I/HtcTextSelection(30023): (onFocusChanged) stopTextSelectionMode
05-31 18:31:34.984: I/HtcTextSelection(30023): (onFocusChanged) dismissQuickAction
05-31 18:31:34.984: I/HtcTextSelection(30023): (onFocusChanged) mIsInTextSelectionMode = false
05-31 18:31:35.034: D/dalvikvm(30023): DexOpt: --- BEGIN 'ads-2141571499.jar' (bootstrap=0) ---
05-31 18:31:35.323: D/dalvikvm(30023): DexOpt: --- END 'ads-2141571499.jar' (success) ---
05-31 18:31:35.323: D/dalvikvm(30023): DEX prep '/data/data/com.quad.equa/cache/ads-2141571499.jar': unzip in 0ms, rewrite 290ms
05-31 18:31:35.573: I/Ads(30023): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":0,"session_id":"10718683671789989957","u_sd":1.5,"seq_num":"1","slotname":"a15191411a98286","u_w":320,"msid":"com.quad.equa","js":"afma-sdk-a-v6.4.1","ms":"wJ-iV8c0M8aPxLjIDF2tiuydOAZtgucqOYxrH_rC_il4R8ukh8guYElD8Q6K1aTcVovIgCrTMbs93UHN2CW6WylrvhcItIsZNxBM9MBo6gAHC41ufRI-xrkDBBjl10-m0moCTnRWUlznfnHK3nFPxUGvJ70kE0lCWfZZ7PNLahIqa8o6q6Kf5I8Bktln7v7G2ZXr0pEbeWZjf1XVA8yd0_rUBJmc1Yn8CQ-ke5qm4Kuqchhj-s2_roY9qkNjRjmniZfiPtBkQrfPnbtJbsdQu-P9r3LtXcwgSMP4OnZODWuqu6BvO2o7TqV3GdBKVghaPRgDMhiolK7aMfWNBgG24g","mv":"80210006.com.android.vending","isu":"9B33F819BBF6446C23116F898BCD7877","bas_off":0,"format":"320x50_mb","oar":0,"net":"wi","app_name":"3.android.com.quad.equa","hl":"lt","ad_pos":{"height":0,"visible":1,"y":573,"x":0,"width":480},"gnt":8,"u_h":533,"pt":1,"carrier":"24602","bas_on":0,"ptime":0,"u_audio":1});</script></head><body></body></html>
05-31 18:31:35.703: D/webkit-timers(30023): [JWebCoreJavaBridge::resume] >> do resume
05-31 18:31:36.303: D/dalvikvm(30023): GC_CONCURRENT freed 266K, 40% free 3539K/5895K, external 0K/0K, paused 4ms+15ms
05-31 18:31:36.673: W/webcore(30023): Can't get the viewWidth after the first layout
05-31 18:31:36.793: I/Ads(30023): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=10718683671789989957&u_sd=1.5&seq_num=1&u_w=320&msid=com.quad.equa&js=afma-sdk-a-v6.4.1&ms=wJ-iV8c0M8aPxLjIDF2tiuydOAZtgucqOYxrH_rC_il4R8ukh8guYElD8Q6K1aTcVovIgCrTMbs93UHN2CW6WylrvhcItIsZNxBM9MBo6gAHC41ufRI-xrkDBBjl10-m0moCTnRWUlznfnHK3nFPxUGvJ70kE0lCWfZZ7PNLahIqa8o6q6Kf5I8Bktln7v7G2ZXr0pEbeWZjf1XVA8yd0_rUBJmc1Yn8CQ-ke5qm4Kuqchhj-s2_roY9qkNjRjmniZfiPtBkQrfPnbtJbsdQu-P9r3LtXcwgSMP4OnZODWuqu6BvO2o7TqV3GdBKVghaPRgDMhiolK7aMfWNBgG24g&mv=80210006.com.android.vending&isu=9B33F819BBF6446C23116F898BCD7877&bas_off=0&format=320x50_mb&oar=0&net=wi&app_name=3.android.com.quad.equa&hl=lt&gnt=8&u_h=533&carrier=24602&bas_on=0&ptime=0&u_audio=1&u_so=p&imbf=%40installed_markets%40&output=html®ion=mobile_app&u_tz=180&client_sdk=1&ex=1&slotname=a15191411a98286&gsb=wi&caps=interactiveVideo_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=48" type: "admob" afmaNotifyDt: "null" activationOverlayUrl: "null" useWebViewLoadUrl: "false">
05-31 18:31:36.873: I/Ads(30023): Ad url modified to http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=10718683671789989957&u_sd=1.5&seq_num=1&u_w=320&msid=com.quad.equa&js=afma-sdk-a-v6.4.1&ms=wJ-iV8c0M8aPxLjIDF2tiuydOAZtgucqOYxrH_rC_il4R8ukh8guYElD8Q6K1aTcVovIgCrTMbs93UHN2CW6WylrvhcItIsZNxBM9MBo6gAHC41ufRI-xrkDBBjl10-m0moCTnRWUlznfnHK3nFPxUGvJ70kE0lCWfZZ7PNLahIqa8o6q6Kf5I8Bktln7v7G2ZXr0pEbeWZjf1XVA8yd0_rUBJmc1Yn8CQ-ke5qm4Kuqchhj-s2_roY9qkNjRjmniZfiPtBkQrfPnbtJbsdQu-P9r3LtXcwgSMP4OnZODWuqu6BvO2o7TqV3GdBKVghaPRgDMhiolK7aMfWNBgG24g&mv=80210006.com.android.vending&isu=9B33F819BBF6446C23116F898BCD7877&bas_off=0&format=320x50_mb&oar=0&net=wi&app_name=3.android.com.quad.equa&hl=lt&gnt=8&u_h=533&carrier=24602&bas_on=0&ptime=0&u_audio=1&u_so=p&imbf=8009&output=html®ion=mobile_app&u_tz=180&client_sdk=1&ex=1&slotname=a15191411a98286&gsb=wi&caps=interactiveVideo_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=48
05-31 18:31:36.873: I/Ads(30023): Request scenario: Online server request.
05-31 18:31:36.963: E/Ads(30023): IOException connecting to ad url.
05-31 18:31:36.963: I/Ads(30023): The following was caught and handled:
05-31 18:31:36.963: I/Ads(30023): java.net.ConnectException: googleads.g.doubleclick.net/127.0.0.1:80 - Connection refused
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:210)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:440)
05-31 18:31:36.963: I/Ads(30023): at java.net.Socket.connect(Socket.java:1013)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
05-31 18:31:36.963: I/Ads(30023): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
05-31 18:31:36.963: I/Ads(30023): at com.google.ads.internal.f.b(SourceFile:489)
05-31 18:31:36.963: I/Ads(30023): at com.google.ads.internal.f.run(SourceFile:460)
05-31 18:31:36.963: I/Ads(30023): at java.lang.Thread.run(Thread.java:1027)
05-31 18:31:36.963: D/webviewglue(30023): nativeDestroy view: 0x34b118
05-31 18:31:37.172: W/dalvikvm(30023): JNI: DeleteGlobalRef(0xde5b9dc7) failed to find entry (valid=0)
05-31 18:31:37.172: W/dalvikvm(30023): JNI: DeleteGlobalRef(0xde5b9da7) failed to find entry (valid=0)
05-31 18:31:37.172: I/Ads(30023): onFailedToReceiveAd(A network error occurred.)
您是否刪除了addTestDevice行?或者只是將其註釋掉例如:adRequest.addTestDevice(AdRequest.TEST_EMULATOR);這條線 – Shrikant
我根本沒有使用anny的測試設置。 – user2352065
可以請你發佈你的代碼爲admob。 – Shrikant