我正在尝试使用intents在youtube中上传视频。问题是该视频无法在youtube中共享,仅在gmail,blutooth等中才能正常工作。我正在使用的代码是

        Log.d("Share Example", "Share button is clicked");
        String outputFile = pathOfSelected;
        Log.d("Share Example", "outputFileURL: " + outputFile);

        ContentValues content = new ContentValues(4);
        content.put(Video.VideoColumns.TITLE, "My Test");
        content.put(Video.VideoColumns.DATE_ADDED,
        System.currentTimeMillis() / 1000);
        content.put(Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, outputFile);
        ContentResolver resolver = getContentResolver();
        Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
        content);

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("video/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(intent, "Share using"));

有人请帮我整理一下

最佳答案

为我尝试这项工作

        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, share_outputFileName);
    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,getString("");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE,getString("");
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);


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

10-05 20:23
查看更多