1.按钮添加音效功能
SoundPool sp= new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);//第一个参数为同时播放数据流的最大个数,第二数据流类型,第三为声音质量
int music = sp.load(this, R.raw.key_sound, 1); //把你的声音素材放到res/raw里,第2个参数即为资源文件,第3个为音乐的优先级
sp.play(music, 1, 1, 0, 0, 1);就会自动播放, /src/raw文件夹下的key_sound.mp3音乐文件
2.android把字符串内容保存到指定路径
public static void saveFile(String str) {
String filePath = null;
boolean hasSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
if (hasSDCard) {
filePath = Environment.getExternalStorageDirectory().toString() + File.separator + "hello.txt";
} else
filePath = Environment.getDownloadCacheDirectory().toString() + File.separator + "hello.txt";
try {
File file = new File(filePath);
if (!file.exists()) {
File dir = new File(file.getParent());
dir.mkdirs();
file.createNewFile();
}
FileOutputStream outStream = new FileOutputStream(file);
outStream.write(str.getBytes());
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}