【发布时间】:2014-06-06 02:53:08
【问题描述】:
我正在使用DownloadManager 将图像下载到系统的图库,然后在广播接收器中(一旦下载成功)使用 Intent 将图像设置为壁纸。
一切正常,但最近在 4.4 上,我开始在照片/Google+ 应用中遇到异常,因为它需要的是内容 URI,而不是文件 URI。
所以我的问题是,是否有人知道如何将完整的文件路径/URI (file://) 转换为内容样式 URI (content://)?
抱歉缺少源代码,我远离有源代码的计算机,但我希望没有它的问题有意义,从完整路径获取内容样式 uri。
编辑:
图像被复制到系统的图库或媒体库中,而不是保存在我的应用程序内部存储中。
这是我要转换的示例:
file:///storage/emulated/0/Pictures/Rockstar/image.jpg
到
content://media/internal/images/media/445
编辑 2:
这是我从 Google+ 应用中得到的错误:
04-21 10:50:35.090: E/AndroidRuntime(7220): FATAL EXCEPTION: main
04-21 10:50:35.090: E/AndroidRuntime(7220): Process: com.google.android.apps.plus, PID: 7220
04-21 10:50:35.090: E/AndroidRuntime(7220): java.lang.RuntimeException: Unable to resume activity
{com.google.android.apps.plus/com.google.android.apps.photos.phone.SetWallpaperActivity}:
java.lang.IllegalArgumentException: Image URI must be of the content scheme type
这是我用来让用户设置壁纸的代码:
String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
Uri u = Uri.parse(uriString);
Intent wall_intent = new Intent(Intent.ACTION_ATTACH_DATA);
wall_intent.setDataAndType(u, "image/*");
wall_intent.putExtra("mimeType", "image/*");
Intent chooserIntent = Intent.createChooser(wall_intent,
"Set As");
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(chooserIntent);
}
uriString 在哪里:
file:///storage/emulated/0/Pictures/Rockstar/image.jpg
【问题讨论】:
标签: android