直接上代码啦,调用铃声
MediaPlayer mp=new MediaPlayer();
try {
mp.setDataSource(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mp.prepare();
mp.start();
} catch (IOException e) {
e.printStackTrace();
}
调用震动需要权限授权申请
<uses-permission android:name="android.permission.VIBRATE"/>
调用代码
Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
long [] pattern = {100,400,100,400}; // 停止 开启 停止 开启
vibrator.vibrate(pattern,2); //重复两次上面的pattern 如果只想震动一次,index设为-1
//取消代码
vibrator.cancel();
Toast调用代码
public void showToast(String text) {
if(toast == null) {
toast = Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT);
} else {
toast.setText(text);
toast.setDuration(Toast.LENGTH_SHORT);
}
toast.show();
}
public void cancelToast() {
if (toast != null) {
toast.cancel();
}
}