我使用DownloadManager将图像下载到系统的图库,然后在广播接收器中(一旦下载成功)使用Intent将图像设置为壁纸.
一切都工作正常,但最近在4.4我开始在Photos/Google +应用程序中得到一个例外,因为它期望内容URI而不是文件URI.
所以我的问题是,如果有人知道如何将完整的文件路径/ URI(文件://)转换为内容样式URI(内容://)?
很抱歉缺少源代码,我远离拥有源代码的计算机,但我希望没有它的问题是有道理的,从完整的路径获取内容样式uri.
编辑:
图像将复制到系统的图库或媒体库中,而不会保存在我的应用内部存储中.
以下是我想要转换的示例:
file:///storage/emulated/0/Pictures/Rockstar/image.jpg
Run Code Online (Sandbox Code Playgroud)
至
content://media/internal/images/media/445
Run Code Online (Sandbox Code Playgroud)
编辑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
Run Code Online (Sandbox Code Playgroud)
这是我用来让用户设置壁纸的代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
在哪里 …
我在应用程序中使用ActionBarSherlock以及ShareActionProvider.我正在使用共享意图以与ActionBarSherlock示例非常相似的方式共享图像:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*");
Run Code Online (Sandbox Code Playgroud)
一切正常,唯一的问题是我的应用程序也接受共享图像内容("图像/*"),因此它显示在应用程序列表中.有没有办法解决?
编辑:
这是我的意图过滤器:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud) android actionbarsherlock android-actionbar shareactionprovider