2012-12-26 48 views
0

我無法將音頻文件附加到像三星GalaxyS2,Nexus等三星設備的一些我不知道最新的問題。我能夠附加所有其他devices.Please某人幫助我爲這個issue.My代碼如下:無法將音頻文件附加到三星設備

Intent sendIntent = new Intent(Intent.ACTION_SEND); 

      sendIntent.putExtra("sms_body", 
        getResources().getText(R.string.Message)); 
      sendIntent.setClassName("com.android.mms", 
        "com.android.mms.ui.ComposeMessageActivity"); 


      AssetManager mngr = getAssets(); 
      InputStream path = null; 
      try { 
       path = mngr.open("*.mp3"); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      BufferedInputStream bis = new BufferedInputStream(path, 1024); 

      // get the bytes one by one 
      int current = 0; 
      // 
      try { 
       while ((current = bis.read()) != -1) { 

        baf.append((byte) current); 
       } 
      } catch (IOException e) { 
       // /TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      byte[] bitmapdata = baf.toByteArray(); 

      File file = new File(Environment.getExternalStorageDirectory() 
        .getAbsolutePath(), "*.mp3"); 

      // if (file.exists() == true) { 
      // } else { 
      // Log.v("directory is created", "new dir"); 
      // file.mkdir(); 
      // } 

      FileOutputStream fos; 

      try { 
       fos = new FileOutputStream(file); 
       fos.write(bitmapdata); 
       fos.flush(); 
       fos.close(); 
      } catch (FileNotFoundException e) { 
       // handle exception 
      } catch (IOException e) { 
       // handle exception 
      } 

      final File file1 = new File(Environment 
        .getExternalStorageDirectory().getAbsolutePath(), 
        "*.mp3"); 
      Uri uri = Uri.fromFile(file1); 

      Log.e("Path", "" + uri); 

      sendIntent.putExtra(Intent.EXTRA_STREAM, uri); 
      sendIntent.setType("audio/mp3"); 
      // sendIntent.putExtra(Intent.EXTRA_STREAM, mms_uri.toString()); 

      startActivity(Intent.createChooser(sendIntent, "")); 
      // startActivity(sendIntent); 

     } catch (Exception e) { 
      Toast.makeText(getApplicationContext(), 
        "SMS faild, please try again later!", Toast.LENGTH_LONG) 
        .show(); 
      e.printStackTrace(); 
     } 
+0

logcat說什麼? –

+0

Log cat中沒有出現任何錯誤,並且還獲得了存儲我的音頻文件的SD卡的正確路徑。唯一的問題是我無法將音頻文件附加到Galaxy S2,Nexus等某些三星設備上。我成功地將音頻文件附加到所有其他devices.I不知道我在上面的代碼中錯了什麼? – Biginner

回答

1

請勿通過調用setClassName()明確設置的類名。相反,只需按照here所述設置動作,類型和額外。

+0

Log cat中沒有出現任何錯誤,並且還獲取了存儲我的音頻文件的SD卡的正確路徑。唯一的問題是我無法將音頻文件附加到Galaxy S2,Nexus等三星設備中。我成功地將音頻文件附加到所有其他devices.I不知道我在上面的代碼中錯了什麼? – Biginner

+0

我必須使用什麼setType將音頻文件附加到MMS? – Biginner

+0

@Romil使用''audio/*「'作爲音頻文件。 –

0

您假定設備上有ExternalStorage,即sd卡可用。您的S2或Nexus可能沒有SD卡。我以前見過這個問題。

+0

要解決這個問題,我該怎麼做? – Biginner