【问题标题】:android set home wallpaper using intent from drawableandroid使用drawable的意图设置家庭壁纸
【发布时间】:2013-11-24 21:01:27
【问题描述】:

我是 android 开发的新手,我想设置带有可绘制图像的家庭壁纸。 我写了这段代码来设置但不工作,起初我在视觉 android 设备中有对话框,但接下来当我点击作为背景时,我收到这条消息:

"使用相机前需要插入sd卡..."

我还需要使用我的可绘制对象作为图像源... 这是我的代码:

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
MimeTypeMap map = MimeTypeMap.getSingleton();
String mimeType = map.getMimeTypeFromExtension("jpg");    
 Uri uri = Uri.parse("@drawable/wall_7");         
intent.setDataAndType(uri,"image/jpeg" );
intent.putExtra("mimeType", mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);      
this.startActivityForResult(Intent.createChooser(intent,"Set as"),200);

我将有一个可滑动的壁纸,而不是固定图像。我正在使用这个意图 bcs 它让用户裁剪图像。

【问题讨论】:

    标签: android android-intent drawable wallpaper


    【解决方案1】:

    首先你需要把这个权限添加到你的 manifest.xml 中

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

    然后你可以使用它来设置它使用壁纸管理器:

    WallpaperManager wallpaperManager = WallpaperManager.getInstance(MyActivity.this); 
    Drawable drawable = getResources().getDrawable(R.drawable.wallpaper_img);
                    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                    wallpaperManager.setBitmap(bitmap);
    

    或者你可以使用this 使用意图设置壁纸

    【讨论】:

      【解决方案2】:

      您可以使用 android:background 标签直接在您的 xml 文件中设置背景。如果您有任何进一步的疑问,请告诉我。

      【讨论】:

      • 问题是关于设置设备主页壁纸图片,而不是为活动设置背景图片。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多