Android的作为壁纸功能 [英] Android used as Wallpaper functionality

查看:150
本文介绍了Android的作为壁纸功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序里面,我有一个图片库。 ID:当我选择一个图像,它在的ImageView Android的另一个片段打开=@ + ID / gallery_image),并显示在全屏模式下。

I am developing an app inside which I have an image gallery. When I select an image, it opens in another fragment in an imageView (android:id="@+id/gallery_image") and show in full screen mode.

一切都工作得很好。但我需要一个图像设置为设备壁纸的功能。打开图像后,当用户preSS菜单键,选项菜单中会出现一个名为用作墙纸只有一个菜单项。在单击该项目,Android的默认的意图设置为墙纸(可​​能是 android.intent.action.SET_WALLPAPER )会给用户一个选项来设置图片作为壁纸该设备。裁剪或其他墙纸设置功能将由机器人来处理。

Everything works well. But I need the functionality of setting that image as device wallpaper. After opening an image, when user press menu button, option menu will appear with only one menu item named 'use as Wallpaper'. On clicking that item, the default intent of android to set as wallpaper (may be android.intent.action.SET_WALLPAPER) will give user an option to set that image as wallpaper for that device. The cropping or other wallpaper setting functionality will be handled by android.

我不知道如何打开墙纸设置意图和在同一时间的形象传递给意图设置为墙纸。请给我一些工作code例子。或者有没有更好的方法呢?

I don't know how to open the wallpaper setting intent and at the same time pass that image to that intent to set as wallpaper. Please give me some working code example. Or is there any better way to do that?

推荐答案

更新:

对于图像传递给本地壁纸应用程序:

For passing the image to the native wallpaper app:

Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));

您可以创建文本菜单设置为你的应用程序的墙纸键,当一个项目用户点击该项目,你使用这个code。

You can create an item in contextMenu as Set as wallpaper in your app and when the user taps that item, you use this code.

调用此方法对所选图像设置为墙纸:

Call this method for setting the selected image as Wallpaper:

public void setWallpaper() {

        Context context = this.getBaseContext(); 
        Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),mImageIds[pos]);
        context.setWallpaper(mBitmap);
}

而在 Android清单文件中添加以下权限:

  <uses-permission android:name="android.permission.SET_WALLPAPER" />

这篇关于Android的作为壁纸功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆