Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 startActivity即使在添加Intent.FLAG\u ACTIVITY\u NEW\u任务后仍不工作_Android_Android Intent_Task_Android Context - Fatal编程技术网

Android startActivity即使在添加Intent.FLAG\u ACTIVITY\u NEW\u任务后仍不工作

Android startActivity即使在添加Intent.FLAG\u ACTIVITY\u NEW\u任务后仍不工作,android,android-intent,task,android-context,Android,Android Intent,Task,Android Context,我的应用程序有一个共享文件的类。从目标27升级到目标29后,它将停止使用AndroidRuntimeException: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 所以我添加了标志,但仍然得到完全

我的应用程序有一个共享文件的
类。从目标27升级到目标29后,它将停止使用
AndroidRuntimeException

 android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
所以我添加了标志,但仍然得到完全相同的错误。 为什么我在设置标志后仍会出现错误?清单文件中没有android:launchMode

这是已添加标志的方法:

public class Share {
  public static void sharefile(Context context, String filename) {
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sharingIntent.putExtra(Intent.EXTRA_STREAM, (getUriFromFile(new File(filename)));
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, filename);
    sharingIntent.setType((new FileChooser()).getMimeType(filename));
    context.startActivity(Intent.createChooser(sharingIntent, filename));
}
这就是它的名称:

   Share.sharefile(getApplicationContext(), filename);

不要传递应用程序上下文,而是传递调用此共享方法的活动上下文。事实上,这可以防止出现错误,谢谢!!但是,我得到了另一个(没有实际崩溃):
java.lang.SecurityException:权限拒绝:读取androidx.core.content.FileProvider uri content://从pid=25134,uid=1000需要导出提供程序,或者grantUriPermission()