我正在編寫一個Android應用程序,使用共享意圖將sdcard中的mp4格式視頻上傳到youtube。當我安裝到手機上時,它第一次完美運行。但是,重新啓動應用後,我無法再分享它。如果我分享到whatsapp,「共享失敗」apear。如果我點擊youtube,我會在logcat上看到「沒有媒體uri(s)」消息。在同一部手機上重新安裝或重新啓動手機無法解決問題。Android共享意圖無法啓動
即使我將應用程序安裝在與其他Android設備相同的代碼中,它也只能運行一次。當我重新啓動應用程序,同樣的問題發生。
我從這個網站代碼: Trouble with youtube upload
這是我的代碼:
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"));
}
});
附:有紅顏色沒有錯誤的logcat的
問題將sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
你試圖與分析[android.intentintercept]這個問題(https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc。 android.intentintercept)與您的程序並將結果與其他程序的上傳進行比較? – k3b