如何将音频文件附加到彩信中的Andr​​oid? [英] How to attach audio file to MMS in Android?

查看:103
本文介绍了如何将音频文件附加到彩信中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要附加的音频文件MMS.How这样做呢?我发现了很多SO以及对护目镜,但仍然没有得到RHE合适的解决方案yet.So有人帮助我为这个issue.My code是因为:

I want to attach audio file to MMS.How to do that?I found a lot on SO as well as on Goggle but still not got rhe right solution yet.So someone help me for my this issue.My code is as:

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.parse(文件:///mnt/sdcard/*.mp3);
                Log.e(路径,+ URI);

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

            sendIntent.putExtra(Intent.EXTRA_STREAM, uri);

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

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

请告诉我,我错了,上面code?

Please tell me where i am wrong in above code?

推荐答案

请在您的场景中使用这个片段:

Please use this snippet in your scenario:

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");

这篇关于如何将音频文件附加到彩信中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆