如何在Android中将音频文件附加到彩信?
我想将音频文件附加到彩信。如何执行此操作?我在SO和Goggle上找到了很多,但仍然没有找到正确的解决方案。因此,有人帮助我解决此问题。我的代码如下:如何在Android中将音频文件附加到彩信?,android,android-intent,Android,Android Intent,我想将音频文件附加到彩信。如何执行此操作?我在SO和Goggle上找到了很多,但仍然没有找到正确的解决方案。因此,有人帮助我解决此问题。我的代码如下: Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("audio/mp3"); sendIntent.putExtra("sms_body", getResources(
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(“file:///mnt/sdcard/*.mp3”);
Log.e(“路径”,“uri”)
请告诉我上面的代码哪里错了?请在您的场景中使用此代码片段:
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");
事实上,我做了和你想说的一样的事情。仍然有问题。我已经将我正在使用的代码传递给你…如果它不起作用,那么让我知道你在哪一点上遇到了问题,并将日志也传递给我。我没有得到任何强制关闭,但唯一的问题是我不能将音频文件附加到彩信。我能够已成功将音频文件存储到SD卡。请阅读您的日志,这一定是因为您没有传递正确的URI路径。我在日志中获得了正确的路径,但仍然无法附加它。
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");