我有一个壁纸应用程序,允许用户直接从应用程序设置壁纸。在这里,我将图像的http url转换为位图,并调用Android的WallpaperManager
类。
以下是将URL转换为位图并设置到WallpaperManager
位图的代码:
private void setWallpaper() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
Bitmap image = getBitMapFromHttpURL();
if (image != null) {
wallpaperManager.setBitmap(getBitMapFromHttpURL());
image.recycle();
image = null;
} else {
Toast.makeText(this, "Failed to set wallpaper",
Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
} catch (Exception es) {
}
}
在这一行代码wallpaperManager.setBitmap(getBitMapFromHttpURL());
上失败,并抛出以下异常:
java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=21407, uid=10133 requires android.permission.WRITE_SETTINGS, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1465)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:468)
at android.content.ContentResolver.insert(ContentResolver.java:1190)
at android.provider.Settings$NameValueTable.putString(Settings.java:843)
at android.provider.Settings.putString(Settings.java:6792)
at android.provider.Settings.putString(Settings.java:6717)
at android.app.WallpaperManager.willSendBroadcat(WallpaperManager.java:1124)
at android.app.WallpaperManager.setBitmap(WallpaperManager.java:788)
at com.wallie.WallpaperFullScreenActivity.setWallpaper(WallpaperFullScreenActivity.java:453)
at com.wallie.WallpaperFullScreenActivity.access$1(WallpaperFullScreenActivity.java:448)
at com.wallie.WallpaperFullScreenActivity$WallpaperManagerTask.doInBackground(WallpaperFullScreenActivity.java:473)
at com.wallie.WallpaperFullScreenActivity$WallpaperManagerTask.doInBackground(WallpaperFullScreenActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:238)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
什么可能是原因?