我制作了一个动态壁纸。在设置菜单中,我添加了admob。它加载广告就好了。 我已经使用了这个教程http://irinaramazova.blogspot.com/2011/09/add-admob-adview-to-preferenceactivity.html。
但是,当我点击广告时,它给了我安全例外说 -
01-09 14:07:25.098: E/AndroidRuntime(3907): FATAL EXCEPTION: main
01-09 14:07:25.098: E/AndroidRuntime(3907): java.lang.SecurityException: Permission Denial: starting Intent { cmp=ca.jvsh.livewallpaper/com.google.ads.AdActivity (has extras) } from ProcessRecord{2b3b5a38 3907:ca.jvsh.livewallpaper/10137} (pid=3907, uid=10137) requires android.permission.BIND_WALLPAPER
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.os.Parcel.readException(Parcel.java:1322)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.os.Parcel.readException(Parcel.java:1276)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1351)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.app.Activity.startActivityForResult(Activity.java:2827)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.app.Activity.startActivity(Activity.java:2933)
01-09 14:07:25.098: E/AndroidRuntime(3907): at com.google.ads.AdActivity.launchAdActivity(SourceFile:257)
01-09 14:07:25.098: E/AndroidRuntime(3907): at com.google.ads.i.shouldOverrideUrlLoading(SourceFile:134)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:331)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.os.Looper.loop(Looper.java:130)
01-09 14:07:25.098: E/AndroidRuntime(3907): at android.app.ActivityThread.main(ActivityThread.java:3701)
01-09 14:07:25.098: E/AndroidRuntime(3907): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 14:07:25.098: E/AndroidRuntime(3907): at java.lang.reflect.Method.invoke(Method.java:507)
01-09 14:07:25.098: E/AndroidRuntime(3907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
01-09 14:07:25.098: E/AndroidRuntime(3907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
01-09 14:07:25.098: E/AndroidRuntime(3907): at dalvik.system.NativeStart.main(Native Method)
这是清单文件 -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.jvsh.livewallpaper"
android:versionName="1.0.20100908.1"
android:versionCode="1">
<uses-sdk android:minSdkVersion="7" />
<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<service android:name=".LiveWallpaper"
android:label="@string/app_name"
android:icon="@drawable/icon"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="@xml/livewallpaper" />
</service>
<activity android:label="@string/livewallpaper_settings"
android:name=".LiveWallpaperSettings"
android:exported="true"
android:icon="@drawable/icon"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.intent.action.MAIN">
</action>
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:permission="android.permission.BIND_WALLPAPER"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
</activity>
</application>
</manifest>
这是live_wallpaper设置文件 -
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/livewallpaper_settings"
android:key="livewallpaper_settings">
<ca.jvsh.livewallpaper.AdmobPreference android:key="adView">
</ca.jvsh.livewallpaper.AdmobPreference>
<ListPreference
android:key="livewallpaper_background"
android:title="@string/livewallpaper_background_title"
android:summary="@string/livewallpaper_background_summary"
android:entries="@array/livewallpaper_background_names"
android:entryValues="@array/livewallpaper_background_prefix"/>
<ListPreference
android:key="livewallpaper_no_of_balloons"
android:title="@string/livewallpaper_no_of_balloons_title"
android:summary="@string/livewallpaper_no_of_balloons_summary"
android:entries="@array/livewallpaper_no_of_balloons_names"
android:entryValues="@array/livewallpaper_no_of_balloons_prefix"/>
<CheckBoxPreference android:key="livewallpaper_shake"
android:summary="@string/livewallpaper_shake_summary"
android:title="@string/livewallpaper_shake_title"
android:summaryOn="Balloons fall when the phone is shaked"
android:summaryOff="Balloons fall from the top continously"/>
</PreferenceScreen>
这是admob偏好类 -
package ca.jvsh.livewallpaper;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AdmobPreference extends Preference
{
public AdmobPreference(Context context) {
super(context, null);
}
public AdmobPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateView(ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(R.layout.admob_preference, null);
}
}
答案 0 :(得分:0)