2015-02-08 116 views
0

試圖共享多個音頻文件,支持藍牙選項不共享列表來藍牙共享選項即消失的共享選項

enter image description here

我使用下面的代碼

   ArrayList<Uri> pathuri = new ArrayList<Uri>(); 
       for (int i = 0; i < path.length; i++) { 
        pathuri.add(i, Uri.fromFile(new File(path[i]))); 
       } 
       Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
       sendIntent.putExtra(Intent.EXTRA_STREAM, pathuri); 
       sendIntent.setType("audio/*"); 
       startActivity(Intent.createChooser(sendIntent, 
         getString(R.string.send_via))); 

上面的代碼工作在Android 4.4及以下版本可以使用,但不適用於Android 5.0。

雖然下面的代碼嘗試,藍牙選項即將到來。但它給下面的錯誤

   ArrayList<Uri> pathuri = new ArrayList<Uri>(); 
       for (int i = 0; i < path.length; i++) { 
        pathuri.add(i, Uri.fromFile(new File(path[i]))); 
       } 
       Intent sendIntent = new Intent(Intent.ACTION_SEND); 
       sendIntent.putExtra(Intent.EXTRA_STREAM, pathuri); 

OR

   sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, 
         pathuri); 
       sendIntent.setType("audio/*"); 
       startActivity(Intent.createChooser(sendIntent, 
         getString(R.string.send_via))); 

錯誤:

Key android.intent.extra.STREAM expected Parcelable but value was a java.util.ArrayList. The default value <null> was returned. 
Attempt to cast generated internal exception: 
java.lang.ClassCastException: java.util.ArrayList cannot be cast to android.os.Parcelable 

誰能幫我在這個問題上,在此先感謝

回答

0
上述問題

找到解決方案:

    ArrayList<Uri> pathuri = new ArrayList<Uri>(); 
        for (int i = 0; i < path.length; i++) { 
         pathuri.add(i, Uri.fromFile(new File(path[i]))); 
        } 
        Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
        sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, 
          pathuri); 
        sendIntent.setType("*/*"); // previously i am using sendIntent.setType("audio/*"); 
        startActivity(Intent.createChooser(sendIntent, 
          getString(R.string.send_via)));