2017-02-13 60 views
0

文件,我創建了一個應用程序,將一個小時我的代碼不能正常工作後,發送郵件使用動作發送文件。如何分享Android的

當它打開另一個應用程序時,我得到一個錯誤「傳輸這樣的內容類型不支持」shareIt和藍牙文件iamafile沒有發送到...這是我的代碼,我試了很多代碼,但沒有工作。請幫助

File root = new File(Environment.getExternalStorageDirectory(), "/QuizApp/MyAnswer/"+sharedPreferenceUsername +"/"+ editTitle); 
         Uri uri = Uri.fromFile(root); 


         Intent intent = new Intent(); 
         intent.setAction(Intent.ACTION_SEND); 

         intent.setType("*/*"); 
         intent.putExtra(Intent.EXTRA_STREAM, uri); 

         startActivity(intent); 

順便說一句editTitle是一個文件。

回答

0

我有這個工作對多個視頻文件。你可以改變,以便某些行是complient您的需求。

對不起,這是寫在科特林,但我認爲這是不夠理解。

val sharingIntent = Intent(Intent.ACTION_SEND_MULTIPLE) 
     val files = ArrayList<Uri>() 
     files.add(<first file URI>) 
    ... 
     files.add(<n th file URI>) 
     //here set the type wanted. I think that */* is a bad idea because the app could catch it even if the type is not good 
     sharingIntent.type = "video/*" 
     sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files) 
     sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) 
     context.startActivity(sharingIntent) 
+0

感謝的人。它的奇怪它的工作再次,即使我沒有改變的東西 – mime