新奇巧的URI不以Intent.ACTION_VIEW回应 [英] New KitKat URIs dont respond to Intent.ACTION_VIEW

查看:264
本文介绍了新奇巧的URI不以Intent.ACTION_VIEW回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于奇巧已经改变了的URI从采摘到喜欢

Since KitKat has changed the URIs from pickers to likes of

 content://com.android.providers.media.documents/document/image:3951

再没有我的ACTION_VIEW意图工作了。 例如当用户选择一个图像,我用

then none of my ACTION_VIEW intents work anymore. When for example user picks an image, I use

public static void openImage(Fragment f, Uri uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/*");

        f.startActivity(intent);
    }

和Android的画廊和Google+照片上来,但选择的时候,画廊只显示黑屏,照片说:中找不到

and Android Gallery and Google+ Photos come up, but when selected, the Gallery just shows blank screens, Photos says "medium not found"

同样的事情的声音,我以前用

The same thing with sounds, I am used to use

public static void playSound(Fragment f, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "audio/*");

    f.startActivity(intent);
}

它用来表明谷歌播放音乐previous版本,与小白玩对话框的用户界面。随着新的URI,我得到异常,没有应用程序可以处理这个意图。

Which used to show Google Play Music in previous versions, with the little white playing dialog UI. With the new URIs, I get exception that no app is able to handle this intent.

//照片,有趣的是,当你选择画廊,而不是图片在新的KK选择器的用户界面,它返回旧的URI的工作。

// With photos, the funny thing is that, when you choose Gallery instead of the Pictures in the new KK picker UI, it returns the old URIs which work.

任何想法? 是系统的应用程序只是没有准备好新的URI?我应该以某种方式破解新的URI来旧作意图工作?还是我失去了一些东西?

Any ideas? Are the system apps just not ready for the new uris? Should I somehow hack the new uris to old ones to make intents work? Or am I missing something?

谢谢!

推荐答案

解决的办法是标志 FLAG_GRANT_READ_URI_PERMISSION 传递给意图(对奇巧及以上):

The solution is to pass the flag FLAG_GRANT_READ_URI_PERMISSION to the intent (on KitKat and above):

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

另外,还要确保这个开放的内容是从一个ACTION_OPEN_DOCUMENT意图获取如下所述: http://stackoverflow.com/a/三十三万四千二百零九分之一千九百八十七万四千六百四十五

这篇关于新奇巧的URI不以Intent.ACTION_VIEW回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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