Android共享意图无法启动

Android共享意图无法启动,android,android-intent,sharing,Android,Android Intent,Sharing,我正在编写一个Android应用程序,使用共享意图将mp4格式的视频从SD卡上传到youtube。当我第一次安装到手机上时,它运行得非常完美。但是,重新启动应用程序后,我无法再次共享它。如果我分享给whatsapp,“分享失败”apear。如果我点击youtube,我会在logcat上看到“没有媒体uri”的消息。在同一部手机上重新安装或重新启动手机无法解决问题 即使我用相同的代码将应用程序安装到其他android设备上,它也只能完美运行一次。当我重新启动应用程序时,同样的问题发生了 我从这个网

我正在编写一个Android应用程序,使用共享意图将mp4格式的视频从SD卡上传到youtube。当我第一次安装到手机上时,它运行得非常完美。但是,重新启动应用程序后,我无法再次共享它。如果我分享给whatsapp,“分享失败”apear。如果我点击youtube,我会在logcat上看到“没有媒体uri”的消息。在同一部手机上重新安装或重新启动手机无法解决问题

即使我用相同的代码将应用程序安装到其他android设备上,它也只能完美运行一次。当我重新启动应用程序时,同样的问题发生了

我从这个网站上得到了代码:

这是我的代码:

findViewById(R.id.button2).setOnClickListener(new Button.OnClickListener(){ 

        @Override
        public void onClick(View v) {

            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

            sharingIntent.setType("video/*");

            ContentValues content = new ContentValues(4);
            content.put(Video.VideoColumns.DATE_ADDED,
            System.currentTimeMillis() / 1000);
            content.put(Video.Media.MIME_TYPE, "video/mp4");
            content.put(MediaStore.Video.Media.DATA, Environment.getExternalStorageDirectory().getAbsolutePath()+"/myVideo/myVideoTemp.mp4");
            ContentResolver resolver = getBaseContext().getContentResolver();
            Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);


            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,"");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE,"");
            sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);


            startActivity(Intent.createChooser(sharingIntent,"Share video"));
        }         

    });   
p、 美国。logcat上的红色没有错误


添加
sharingcontent.addFlags后解决的问题(Intent.FLAG\u ACTIVITY\u CLEAR\u WHEN\u TASK\u RESET)

尝试以下操作以调用“共享”应用程序:

//Use the URI that points to the video file, in my case, the video file is in local storage (sd card)
Uri fileUri = Uri.fromFile(videoFile);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
//Use the setDataAndType method to provide the URI and MIME type to the file
//Please note, you need to use setDataAndType method to make it work
intent.setDataAndType(fileUri,URLConnection.guessContentTypeFromName(fileUri.toString()));
startActivity(intent);
我有一个博客来展示如何使用本地存储的视频文件从应用程序调用视频播放器。这可能有助于:


您是否尝试分析您的程序的问题,并将结果与其他程序的上载结果进行比较?如果我使用您的代码,是否需要在android manifest.xml中添加任何特殊内容?我的代码从sd卡读取视频文件。因此,如果您从sd卡读取内容,则需要向Android清单文件添加以下权限: