2
我有一個應用程序,它會在特定文本進入時創建聲音通知。爲此,我檢測當前的ringerMode,將ringerMode更改爲正常,播放聲音,以及然後迅速將鈴聲返回到其原始設置。這裏是代碼:訪問服務器內的振鈴模式不起作用
public static AudioManager audio;
audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
ringMode = audio.getRingerMode();
if (ringMode < 2)
//Checks to see if the phones ringer is set to silent, or vibrate
audio.setRingerMode(2);
//vibrates phone in a pattern
long[] pattern = {0, 25};
//long[] pattern = {0, 1000, 100, 100, 100, 100, 100, 1000};
v.vibrate(pattern, -1);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
//delays return back to original volume so notification can be heard
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
audio.setRingerMode(ringMode);
}
}, 4000);
}
這在活動中完全正常,但不在此通知服務中,並且當前放置在onStart方法中。 使用權限android:name =「android.permission.MODIFY_AUDIO_SETTINGS」也被添加到清單中。有任何想法嗎? 謝謝