私は現在、さまざまな間隔でユーザーにサウンドを再生するAndroidアプリケーションを開発しています。Hero(2.2を実行)と1.6エミュレーターで期待どおりに機能する作業コード(以下に含まれています)があります。ただし、友達のXperiax8では動作しません。音が鳴りません。彼には通知トーンが設定されており、テキストなどを受信すると正常に再生されます。
private void prepareAudio(){
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mp = new MediaPlayer();
if(alert != null){
try {
mp.setDataSource(ctx, alert);
} catch (IllegalArgumentException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (SecurityException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (IllegalStateException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (IOException e) {
Log.i("Prepare Audio", e.getMessage());
}
}
am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
}
private void notifyUser(){
if(alert != null){
if (am.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
mp.setLooping(false);
try {
mp.prepare();
} catch (IllegalStateException e) {
Log.i("Notify User", e.getMessage());
} catch (IOException e) {
Log.i("Notify User", e.getMessage());
}
mp.start();
} else {
Log.i("Notify User", "Alarm volume zero");
}
} else {
Log.i("Notify User", "Uri is null");
}
long[] pattern = {0,200,300,600};
v.vibrate(pattern, -1);
}
クラスの初期化時にPrepareAudioが呼び出され、サウンドを再生するたびにユーザーに通知します。電話は必要なときに常に振動するため、notifyUserが確実に呼び出されます。
私の友人がインストールしたバージョンは、Log.iではなくe.printStackTraceを使用しているため、logcatに吐き出されるものはありません。私は彼の電話を手に取ってLog.iのバージョンに更新しようとしていますが、それまでの間、このような断続的な問題を引き起こす可能性のあるコードに明らかに問題がありますか?
ありがとう、