Android 无法将音频文件附加到三星设备
我无法将音频文件连接到一些三星设备,如三星GalaxyS2、Nexus等。我不知道问题出在哪里。我可以连接所有其他设备。请有人帮助我解决此问题。我的代码如下:Android 无法将音频文件附加到三星设备,android,android-intent,Android,Android Intent,我无法将音频文件连接到一些三星设备,如三星GalaxyS2、Nexus等。我不知道问题出在哪里。我可以连接所有其他设备。请有人帮助我解决此问题。我的代码如下: Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra("sms_body", getResources().getText(R.string.Message));
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();
}
不要通过调用
setClassName()
来显式设置类名。相反,只需按说明设置操作、类型和额外设置。您假设设备上有外部存储,即sd卡可用。您的S2或Nexus可能没有sd卡。我以前见过这个问题。Log cat中没有出现任何错误,也找到了存储音频文件的SD卡的正确路径。唯一的问题是我无法将音频文件附加到某些三星设备上,如Galaxy S2,Nexus等。我正在成功地将音频文件连接到所有其他设备。我不知道我在上述代码中的错误在哪里?在Log cat中没有得到任何错误,并且还获得了存储音频文件的SD卡的正确路径。唯一的问题是我无法将音频文件连接到某些三星设备,如Galaxy S2,Nexus等。我正在成功地将音频文件连接到所有其他设备。我不知道上面的代码哪里错了?将音频文件连接到彩信时必须使用什么设置类型?@Romil使用“Audio/*”
连接音频文件。实际上我以前做过,但仍然遇到同样的问题。要克服这个问题,我应该怎么做?