Intent intent = new Intent();

intent.setAction(Intent.ACTION_SEND);
intent.setType("video/3gpp");
intent.putExtra(Intent.EXTRA_STREAM, videoURI);
startActivity(Intent.createChooser(intent,"Upload video via:"));

我用上面的代码把3GP视频上传到YouTube上
但它引发了以下异常。
我不明白日期异常和媒体上传之间的关系
05-04 13:04:59.315: ERROR/AndroidRuntime(10671): FATAL EXCEPTION: Thread-12
05-04 13:04:59.315: ERROR/AndroidRuntime(10671): java.lang.NullPointerException
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.util.Calendar.setTime(Calendar.java:1325)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.SimpleDateFormat.format(SimpleDateFormat.java:818)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.text.DateFormat.format(DateFormat.java:376)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity.a(SourceFile:183)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at com.google.android.apps.uploader.clients.j.run(SourceFile:348)
05-04 13:04:59.315: ERROR/AndroidRuntime(10671):     at java.lang.Thread.run(Thread.java:1019)

最佳答案

当我使用Uri.fromFile()获取视频的uri时,遇到了同样的错误。解决方案是使用ContentProvider创建uri:

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

07-27 19:22