Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set wallpaper in android

Shulou Source: shulou.com Published: 2022-05-31 23:51:54 10月03日 Update

This article mainly introduces "how to set wallpaper in android". In daily operation, I believe many people have doubts about how to set up wallpaper in android. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to set wallpaper in android". Next, please follow the editor to study!

1. Call the Intent.ACTION_ATTACH_DATA of the system, and the Intent will evoke all the programs for setting wallpaper and setting contact profile pictures. Users can choose through ChooseActivity:

The Intent is a standard Intent, so all settings support

Intent intent = new Intent (Intent.ACTION_ATTACH_DATA); intent.addFlags (Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra ("mimeType", "image/*"); Uri uri = Uri.parse (MediaStore.Images.Media .insertImage (getActivity (). GetContentResolver (), ((BitmapDrawable) wallpaper). GetBitmap (), null, null); intent.setData (uri) StartActivityForResult (intent, SET_WALLPAPER)

2. Set via WallpaperManager

This method can directly set the picture as wallpaper, which is used for Android systems on all platforms, but cannot crop / adjust the picture.

Try {WallpaperManager wpm = (WallpaperManager) getActivity (). GetSystemService (Context.WALLPAPER_SERVICE); if (wallpaper! = null) {wpm.setBitmap (bitmap); Log.i ("xzy", "wallpaper not null");} catch (IOException e) {Log.e (TAG, "Failed to set wallpaper:" + e);}

You need to declare permissions in AndroidManifest.xml:

At this point, the study on "how to set up wallpaper in android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Learning pictures wallpaper methods more programs systems help practical next you can pass avatars platforms articles permissions standards theories users knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft MySQL MariaDB Xiaomi