1

我想将音频文件附加到 MMS。如何做到这一点?我在 SO 和 Goggle 上找到了很多,但仍然没有找到正确的解决方案。所以有人帮我解决这个问题。我的代码如下:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("audio/mp3");
            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);

// Uri uri = Uri.parse("file:///mnt/sdcard/*.mp3"); Log.e("路径", "" + uri);

            sendIntent.putExtra(Intent.EXTRA_STREAM, uri);

            // sendIntent.putExtra(Intent.EXTRA_STREAM, mms_uri.toString());

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

请告诉我上面的代码哪里错了?

4

1 回答 1

0

请在您的场景中使用此代码段:

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.putExtra("text-body", "if you are sending text");    
sendIntent.putExtra("num", "number");

sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("ur file path"));
sendIntent.setType("audio/3gp");
于 2012-12-25T08:39:24.013 回答