Witam,
ostatnio wziąłem się za apkę której zadaniem ma być wyświetlenie reklamy. Problem w tym, że gdy wpisuję w kodzie ID reklamy przykładowej to reklama się ładnie wyświetla. Natomiast gdy dodaję swój ID to już nie.
Dodam, że w kodzie innej APK-i gdy dodam mój ID to reklama normalnie się wyświetla. W czym może być problem? Czy ma znaczenie to, że APK-a w której poprawnie wyświetla się reklama z moim ID jest w Android Market (w sensie czy jest to warunek aby reklama poprawnie się wyświetliła)? Czy może w mojej nowej aplikacji jest zbyt mało użytecznych widgetów i system wyświetlania reklam "myśli" że zadaniem apki jest tylko i wyłącznie pokazanie reklamy i nic poza tym w związku z tym ją blokuje? Czy wreszcie może mam błąd w kodzie? Zamieszczam kod APK-i w której nie chce się pokazać reklama z moim ID:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<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"
android:resizeableActivity = "true">
<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.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>
strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ReklamaGoogle</string>
<string name="hello_world">Hello world!</string>
<string name="banner_ad_unit_id">ca-app-pub-MOJ_ID</string>
</resources>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
MainActivity.java:
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.provider.Settings;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String androidId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(md5(androidId).toUpperCase())
.build();
adView.loadAd(adRequest);
}
public String md5(String s) {
try {
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}