バックグラウンドで実行されているサービスがあります。ある瞬間、このサービスは新しいアクティビティ RingAlarm を呼び出しています。
名前が言うように、このアクティビティはアラーム プレーヤーです。そのため、ユーザーがボタンを押すまでサウンドが再生されます。
画面がロックされているときに試したときを除いて、すべてが良かった. その後、サウンドが再生されていないことがわかりました。
画面を取得してロックを解除するには、これを使用しています:
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
wakeLock.acquire();
KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
keyguardLock.disableKeyguard();
着信音を再生するには、これを使用します。
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if(alert == null){
// alert is null, using backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alert == null){ // I can't see this ever being null (as always have a default notification) but just incase
// alert backup is null, using 2nd backup
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
}
}
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(this, alert);
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mPlayer.setLooping(true);
mPlayer.prepare();
mPlayer.start();
}
catch(Exception e) {
//TODO : Implement Error Checking
e.printStackTrace();
Log.e("MediaPlayer", "Error while playing!");
}
多分私は何か間違ったことをしている...何か考えはありますか?
更新(エラー)
10-28 17:49:59.562: I/MediaPlayer(3193): it is a Ringtone type is : 4
10-28 17:49:59.820: E/RingtoneManager(3193): getActualDefaultRingtoneUri : content://media/internal/audio/media/60
10-28 17:49:59.820: E/RingtoneManager(3193): Uri.parse(uriString) : content://media/internal/audio/media/60
10-28 17:49:59.828: I/MediaPlayer(3193): It is a Not a DRM RingTone: return NULl
10-28 17:49:59.828: I/MediaPlayer(3193): path is null
まだ問題があります。私は本当にそれで立ち往生しています。問題はメディアプレーヤーではないことがわかりました。問題は、デバイスがロックモードになっているときに、アプリケーションが再び起動したときに適切に動作しなかったため、振動も機能していないことです。
logcat で次の警告が表示されます。
10-29 18:10:07.851: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection
10-29 18:10:07.851: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection
10-29 18:10:07.867: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection
10-29 18:10:07.875: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): beginBatchEdit on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): endBatchEdit on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection
10-29 18:10:07.882: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): beginBatchEdit on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): endBatchEdit on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getExtractedText on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getTextBeforeCursor on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getSelectedText on inactive InputConnection
10-29 18:10:07.898: W/IInputConnectionWrapper(19683): getTextAfterCursor on inactive InputConnection
何か案が?
ありがとう