2 johnny2004 Johnny2004 于 2012.11.15 19:14 提问

Launcher,must have permission android.permission.SET_WALLPAPER_HINTS

有空帮我看下这问题,万分感想。

(在虚拟机上运行)

11-14 10:09:06.565: E/AndroidRuntime(402): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hskj.iphonehome/com.hskj.iphonehome.Launcher}: java.lang.SecurityException: Access denied to process: 402, must have permission android.permission.SET_WALLPAPER_HINTS
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1754)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread.access$1500(ActivityThread.java:156)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1000)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.os.Handler.dispatchMessage(Handler.java:130)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.os.Looper.loop(SourceFile:351)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread.main(ActivityThread.java:3821)
11-14 10:09:06.565: E/AndroidRuntime(402):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 10:09:06.565: E/AndroidRuntime(402):  at java.lang.reflect.Method.invoke(Method.java:538)
11-14 10:09:06.565: E/AndroidRuntime(402):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
11-14 10:09:06.565: E/AndroidRuntime(402):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
11-14 10:09:06.565: E/AndroidRuntime(402):  at dalvik.system.NativeStart.main(Native Method)
11-14 10:09:06.565: E/AndroidRuntime(402): Caused by: java.lang.SecurityException: Access denied to process: 402, must have permission android.permission.SET_WALLPAPER_HINTS
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.os.Parcel.readException(Parcel.java:1353)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.os.Parcel.readException(Parcel.java:1307)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.IWallpaperManager$Stub$Proxy.setDimensionHints(IWallpaperManager.java:343)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.WallpaperManager.suggestDesiredDimensions(WallpaperManager.java:717)
11-14 10:09:06.565: E/AndroidRuntime(402):  at com.hskj.iphonehome.Launcher.setWallpaperDimension(Launcher.java:482)
11-14 10:09:06.565: E/AndroidRuntime(402):  at com.hskj.iphonehome.Launcher.onCreate(Launcher.java:322)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
11-14 10:09:06.565: E/AndroidRuntime(402):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1699)
11-14 10:09:06.565: E/AndroidRuntime(402):  ... 11 more

各位大侠,我明明加了这权限。为什么还会报错。

4个回答

zhongyuanceshi
zhongyuanceshi   2012.11.15 21:57

是运行出错还是编译不过?好像是运行出错吧,没有fatal吗,用DDMS调试看下

ce_la_vie
ce_la_vie   2012.11.16 13:40
java.lang.SecurityException: Access denied to process: 402, must have permission android.permission.SETWALLPAPERHINTS

根据这句,你需要在你的代码中添加一句权限:

<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
ce_la_vie
ce_la_vie 嗯,可能是呢
5 年多之前 回复
Johnny2004
Johnny2004 嗯。没有报新的错误,估计是模拟器的问题吧????
5 年多之前 回复
ce_la_vie
ce_la_vie 你加上权限之后还是报这个错吗?有没有新的错误提示?
5 年多之前 回复
ce_la_vie
ce_la_vie 那你把关键代码贴一下啊
5 年多之前 回复
Johnny2004
Johnny2004 我明明加了这权限。为什么还会报错。
5 年多之前 回复
xiaoxiaobian3310903
xiaoxiaobian3310903   2012.11.16 14:34

缺少权限,需要加上<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>

Johnny2004
Johnny2004   2012.11.16 18:26




private static final int WALLPAPER_SCREENS_SPAN = 1;

WallpaperManager wpm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);

    Display display = getWindowManager().getDefaultDisplay();

    final int width = display.getWidth();
    final int height = display.getHeight();

    wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!