[英]Can't get URI of captured screenshot from intent.getParcelableExtra(Intent.EXTRA_STREAM)!
当我从“ Open With
对话框中选择我的应用程序时,我试图获取刚刚捕获的screenshot
的URI
。 但是我总是从提供的代码示例中的intent.getParcelableExtra(Intent.EXTRA_STREAM)
中获得null。
这是我的intent filter
:
实现了两个intent-filter
第一个:使我的活动成为主要活动和启动程序。
第二个:使其成为图像查看器。(将此活动在系统上注册为图像查看器)
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
这就是我试图从调用我的活动的意图中获取URI
的方式。
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri mediaUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
// Here mediaUri is always null
}
}
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri mediaUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
// Here mediaUri is always null
}
}
引用ACTION_VIEW
的文档 :
输入:getData()是从中检索数据的URI。
因此,将您的代码更改为:
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_VIEW.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri mediaUri = intent.getData();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.