我已按如下方式配置设置活动: 的 XML / wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper android:description="@string/appName" android:thumbnail="@drawable/icon"
xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.xyz.abc.LiveWallpaperSettings"/>
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.abc"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:icon="@drawable/icon"
android:label="@string/appName" >
<service
android:name="CustomWallpaper"
android:label="@string/appName"
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/wallpaper" />
</service>
<activity android:name="com.xyz.abc.LiveWallpaperSettings" >
<intent-filter>
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
</application>
</manifest>
LiveWallpaperSettings java code:
public class LiveWallpaperSettings extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.settings);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
}
}
单击设备上的设置按钮时看到的错误是:
E/AndroidRuntime(13164): java.lang.IllegalStateException: Could not execute method of the activity
E/AndroidRuntime(13164): at android.view.View$1.onClick(View.java:3607)
E/AndroidRuntime(13164): at android.view.View.performClick(View.java:4212)
E/AndroidRuntime(13164): at android.view.View$PerformClick.run(View.java:17476)
E/AndroidRuntime(13164): at android.os.Handler.handleCallback(Handler.java:800)
E/AndroidRuntime(13164): at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(13164): at android.os.Looper.loop(Looper.java:194)
E/AndroidRuntime(13164): at android.app.ActivityThread.main(ActivityThread.java:5371)
E/AndroidRuntime(13164): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13164): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(13164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/AndroidRuntime(13164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/AndroidRuntime(13164): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(13164): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(13164): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13164): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(13164): at android.view.View$1.onClick(View.java:3602)
E/AndroidRuntime(13164): ... 11 more
E/AndroidRuntime(13164): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.xyz.abc/.LiveWallpaperSettings (has e
xtras) } from ProcessRecord{4236f958 13164:com.android.wallpaper.livepicker/u0a10036} (pid=13164, uid=10036) not exported from uid 10073
E/AndroidRuntime(13164): at android.os.Parcel.readException(Parcel.java:1425)
E/AndroidRuntime(13164): at android.os.Parcel.readException(Parcel.java:1379)
E/AndroidRuntime(13164): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1939)
E/AndroidRuntime(13164): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1418)
E/AndroidRuntime(13164): at android.app.Activity.startActivityForResult(Activity.java:3388)
E/AndroidRuntime(13164): at android.app.Activity.startActivityForResult(Activity.java:3349)
E/AndroidRuntime(13164): at android.app.Activity.startActivity(Activity.java:3584)
E/AndroidRuntime(13164): at android.app.Activity.startActivity(Activity.java:3552)
E/AndroidRuntime(13164): at com.android.wallpaper.livepicker.LiveWallpaperPreview.configureLiveWallpaper(LiveWallpaperPreview.java:125)
答案 0 :(得分:0)
我假设您正在尝试设置壁纸,如果是这样您必须在Android清单文件中包含以下权限。
<uses-permission android:name="android.permission.SET_WALLPAPER" />
我希望它能解决你的问题。