こんにちは私は着信音や通知として音を保存する問題があります。 私は自分のセットを取得し続けるトースト - 失敗 - あなたのSDカードを確認Androidの着信音と通知
どこが間違っていますか?
コード:http://pastebin.com/in5ckvk0
こんにちは私は着信音や通知として音を保存する問題があります。 私は自分のセットを取得し続けるトースト - 失敗 - あなたのSDカードを確認Androidの着信音と通知
どこが間違っていますか?
コード:http://pastebin.com/in5ckvk0
問題はここに
String path=Environment.getExternalStorageDirectory().getPath()+"/sdcard/media/ringtone/";
Environment.getExternalStorageDirectory()
では、とにかく着信音を保存するためにいくつかの他のフォルダ名を使用して、あなたに/ SDカードのパスを返します。代わりに/ SDカード/メディア、それはその後、/SDCard/yourPackage/media/
として解釈されるように
のように/ yourPackage /メディアは、それがここに
OK役立ちます私は現在、データを格納するための私のアプリケーションで使用するサンプル・コードを願って私のSDCardに見て、これを使ってみてください。
File newSoundFile;
ContentResolver mCr;
Log.e("check this tag","path for SDCard:"+Environment.getExternalStorageDirectory().getAbsolutePath());
//storing at: /mnt/sdcard/media
File directoryStructure=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Halloween");
//if directory doesn't exist create a directory if that fails too return false
if(!(directoryStructure.exists())){
if(!(directoryStructure.mkdirs())){
return false;
}
}
/*for(int allRing=0;allRing<ringId.length;allRing++)*/{
newSoundFile = new File(directoryStructure, "/"+HalloweenWallpaper.longPressSelected+".mp3");
Uri mUri = Uri.parse("android.resource://"+getApplication().getPackageName()+"/"+ringId[HalloweenWallpaper.longPressSelected]);
mCr = HalloweenWallpaper.this.getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile=null;
Log.e("first check", "here --"+e.getMessage());
return false;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(newSoundFile);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
Log.e("Second Check", "--"+io.getMessage());
return false;
}
}
//STORES SUCCESFULLY
はい、 'Environment.getExternalStorageDirectory()は'とにかくので、 '文字列のパス= Environment.getExternalStorageDirectory()を使用して、代わりに –
をその部分をスキップ/ SDカードのパスあなたを返します。ある、getPath()+"/yourPackage/COM。 ring/media "; ' –
動作しません。/media/ringtone/ –