I have an application of wallpapers where I allow the user to set wallpaper directly from the app. Here I convert http url of image into Bitmap and call WallpaperManager
class of Android.
Following is code for converting URL to bitmap and setting into WallpaperManager
bitmap:
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) {
}
}
It fails on this line wallpaperManager.setBitmap(getBitMapFromHttpURL());
with the following exception:
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)
What can be the reason?
The exception you are getting clearly defines you need to add the permission in Manifest.
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()
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
The logcat is clear:
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()
So you just need to add this permission in your Manifest file:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
under application tag.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With