我创建了一个应用程序,它可以将图像从我的手机 (Samsung Galaxy S2) 上传到我的服务器,使用“共享通过”...
但是,对于我在 Picasa 中在线拥有的图像,我的应用程序并未显示为“共享方式”菜单中的替代选项。我想知道如何能够处理画廊中显示的各种图像 - 本地存储在手机/SD 卡上和远程存储在例如 Picasa 中?
现在我在 mime 类型“image/*”上有 intent-filters,我想这与 Picasa 图像不匹配,出于某种原因(?)。
来 self 的 AndroidManifest.xml:
<activity
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".PublishImageActivity"
android:theme="@style/Theme.Custom" >
<intent-filter >
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".PublishImageActivity"
android:theme="@style/Theme.Custom" >
<intent-filter >
<action android:name="android.intent.action.CHOOSER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
最佳答案
经过一番努力,并使用优秀的应用程序“Intent Intercept”,我发现 picasa 图像的 mime 类型为“text/plain”,并且它们在 Intent.EXTRA_TEXT 中有一个 URL 字符串。
所以我为解决这个问题所做的就是添加像上面那样的 Intent 过滤器,但对于 list 中的“text/plain”;
<intent-filter >
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
..在 Activity 中,检查 Intent.EXTRA_TEXT 的值是否 bundle 在 Intent 中 - 如果是,获取它并检查它是否是 http 链接。如果是 - 从 URL 下载图像;
if (Intent.ACTION_SEND.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_TEXT)) {
Uri uri = Uri.parse((String) extras.getCharSequence(Intent.EXTRA_TEXT));
if (uri != null) {
String scheme = uri.getScheme();
if (scheme.equals("http")) {
downloadImage(uri);
// ...
但是我仍然很好奇是否有更好的方法来处理这个问题?感觉我现在没有任何保证,URL 确实指向图像或其他一些顽皮的东西:-)
关于android - 将 Picasa 图片分享到我的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9602550/