Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法通过“我自己的活动”按意图显示GalleryView_Android_Android Intent - Fatal编程技术网

Android 无法通过“我自己的活动”按意图显示GalleryView

Android 无法通过“我自己的活动”按意图显示GalleryView,android,android-intent,Android,Android Intent,我有以下要求。 当应用程序从服务器接收到图像文件时,它应该在默认图像查看器中自动打开图像 正常情况: 活动是可见的。 从服务器接收到图像文件。 App send Intent.ACTION\u视图 Gallery视图显示下载的图像。 失败案例: 活动不可见。例如,按下Home键并返回发射器。 从服务器接收到图像文件。 App send Intent.ACTION\u视图 什么也没发生 经过反复试验,我们找到了答案 有两个标志要添加 最重要的是,应该使用应用程序上下文而不是活动上下文

我有以下要求。 当应用程序从服务器接收到图像文件时,它应该在默认图像查看器中自动打开图像

正常情况:

活动是可见的。 从服务器接收到图像文件。 App send Intent.ACTION\u视图 Gallery视图显示下载的图像。 失败案例:

活动不可见。例如,按下Home键并返回发射器。 从服务器接收到图像文件。 App send Intent.ACTION\u视图
什么也没发生 经过反复试验,我们找到了答案

有两个标志要添加

最重要的是,应该使用应用程序上下文而不是活动上下文

        final Intent openfileintent = new Intent();
        openfileintent.setAction(android.content.Intent.ACTION_VIEW);
        (*1) openfileintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        (*2) openfileintent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        final File file = sharedfile.getFileInstance();
        openfileintent.setDataAndType(Uri.fromFile(file), sharedfile.getMimeType());
        (*3) getApplicationContext().startActivity(openfileintent);
        final Intent openfileintent = new Intent();
        openfileintent.setAction(android.content.Intent.ACTION_VIEW);
        (*1) openfileintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        (*2) openfileintent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        final File file = sharedfile.getFileInstance();
        openfileintent.setDataAndType(Uri.fromFile(file), sharedfile.getMimeType());
        (*3) getApplicationContext().startActivity(openfileintent);