我有一个以WebM格式创建视频的应用。我想使用Android intent
将此视频发送到Youtube,facebook等
我有代码创建一个意图并启动一个选择器,我可以选择上传到哪里,选择目的地并填写带有标题等的表单。我点击上传按钮和我试图上传的应用程序立即崩溃。
以下是我的相关代码:
Uri videoURI = Uri.fromFile(new File( pathName + fileName));
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setAction(Intent.ACTION_SEND);
intent.setType("video/webm");
intent.putExtra(Intent.EXTRA_STREAM, videoURI);
try {
startActivity(Intent.createChooser(intent,"Upload video via:"));
} catch (android.content.ActivityNotFoundException ex) {
Log.e("MWR", "No Way to Share!");
}
pathName + fileName是SD卡上视频的绝对路径。
以下是Youtube崩溃的相关日志信息
11-02 13:42:43.949: WARN/dalvikvm(4443): threadid=10: thread exiting with uncaught exception (group=0x40018560)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): FATAL EXCEPTION: Thread-12
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): java.lang.NullPointerException
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.util.Calendar.setTime(Calendar.java:1325)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:536)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.SimpleDateFormat.format(SimpleDateFormat.java:818)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.text.DateFormat.format(DateFormat.java:376)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity.a(SourceFile:183)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at com.google.android.apps.uploader.clients.j.run(SourceFile:348)
11-02 13:42:43.949: ERROR/AndroidRuntime(4443): at java.lang.Thread.run(Thread.java:1019)
11-02 13:42:43.956: WARN/ActivityManager(2494): Force finishing activity com.google.android.apps.uploader/.clients.youtube.YouTubeSettingsActivity
11-02 13:42:44.261: ERROR/WindowManager(4443): Activity com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40553f20 that was originally added here
11-02 13:42:44.261: ERROR/WindowManager(4443): android.view.WindowLeaked: Activity com.google.android.apps.uploader.clients.youtube.YouTubeSettingsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40553f20 that was originally added here
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.ViewRoot.<init>(ViewRoot.java:258)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.app.Dialog.show(Dialog.java:241)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.google.android.apps.uploader.clients.SettingsActivity.b(SourceFile:43)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.google.android.apps.uploader.clients.c.onClick(SourceFile:122)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.View.performClick(View.java:2485)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.view.View$PerformClick.run(View.java:9089)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Handler.handleCallback(Handler.java:587)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.os.Looper.loop(Looper.java:123)
11-02 13:42:44.261: ERROR/WindowManager(4443): at android.app.ActivityThread.main(ActivityThread.java:3806)
11-02 13:42:44.261: ERROR/WindowManager(4443): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 13:42:44.261: ERROR/WindowManager(4443): at java.lang.reflect.Method.invoke(Method.java:507)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-02 13:42:44.261: ERROR/WindowManager(4443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-02 13:42:44.261: ERROR/WindowManager(4443): at dalvik.system.NativeStart.main(Native Method)
以下是Facebook崩溃的相关日志:
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): FATAL EXCEPTION: main
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): java.lang.RuntimeException: Unable to start service com.facebook.katana.service.FacebookService@4068d4f8 with Intent { cmp=com.facebook.katana/.service.FacebookService (has extras) }: java.lang.NullPointerException
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2128)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.access$2800(ActivityThread.java:124)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1031)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.os.Looper.loop(Looper.java:123)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.main(ActivityThread.java:3806)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at java.lang.reflect.Method.invoke(Method.java:507)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at dalvik.system.NativeStart.main(Native Method)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): Caused by: java.lang.NullPointerException
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.method.VideoUpload.getRealPathFromURI(VideoUpload.java:127)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.method.VideoUpload.start(VideoUpload.java:148)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.FacebookService.startOp(FacebookService.java:1250)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at com.facebook.katana.service.FacebookService.onStart(FacebookService.java:742)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.Service.onStartCommand(Service.java:428)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2115)
11-02 13:57:40.476: ERROR/AndroidRuntime(4497): ... 10 more
所以,更新:
URI
阻止它启动该过程。
我发现了另一篇关于如何使用URI
创建ContentResolver
的帖子,这解决了这个问题。
但是,它没有超过0%,并说我的视频是0字节,但我相信这可能是我的视频创建的问题。