无法从Android Instant应用启动画廊 [英] Not able to launch Gallery from Android Instant app
问题描述
我创建了一个应用程序,该应用程序从模拟器的images文件夹中拾取图像,并在我的应用程序布局中显示选定的图像.当我将我的应用程序转换为即时应用程序时,从图像文件夹中拾取图像的相同代码将引发异常.我使用了运行时权限READ_EXTERNAL_STORAGE.
I created an app which picks up images from images folder in emulator and displays selected image in my layout of application. When I converted my app to instant app, the same code that picks up images from image folder throws exception. I used runtime permissions READ_EXTERNAL_STORAGE.
我的代码:
private static final int PICK_IMAGE_REQUEST = 234;
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICK_IMAGE_REQUEST);
引发异常:
java.lang.SecurityException: Not allowed to start activity Intent {
act=android.intent.action.GET_CONTENT typ=*/* }
运行时权限代码:
private static final int REQUEST_WRITE_STORAGE = 112;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public boolean checkPermission()
{
int currentAPIVersion = Build.VERSION.SDK_INT;
if(currentAPIVersion>=android.os.Build.VERSION_CODES.M)
{
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
Toast.makeText(MainActivity.this,"Permission Denied...",Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE);
return true;
}
return false;
} else {
return true;
}
} else {
return true;
}
}
有人可以帮助我解决这个问题吗?
Can anyone help me in solving this issue?
推荐答案
即时应用无法访问常规Android应用可以访问的某些功能.例外:
Instant Apps are blocked from accessing some features that regular Android apps can access. The exception:
java.lang.SecurityException: Not allowed to start activity Intent...
意味着您已经找到了一种这样的功能.在这种情况下,它是 Intent.ACTION_GET_CONTENT
,目前不是允许的.随着时间的推移,可能会引入对诸如此类的附加功能的支持.
Means you have found one such feature. In this case it is Intent.ACTION_GET_CONTENT
which is not currently allowed. Support for additional features such as this may be introduced over time.
此外,Instant Apps没有访问外部存储的权限,因此请求访问 READ_EXTERNAL_STORAGE
也不起作用或引发异常.有关支持的权限列表,请参见此处.通过Instant Apps.
In addition, Instant Apps do not have access to read or write from external storage so requesting access to READ_EXTERNAL_STORAGE
will also not work or throw an exception. See here for a list of permissions that are supported by Instant Apps.
这篇关于无法从Android Instant应用启动画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!