2015-05-01 31 views
-1

我正在處理應用程序..但Audiomanager無法正常工作我看不到任何錯誤我的應用程序碰撞在手機上 我在使用AudioManager的BroadCastReciver類時,短信recive和短信的文本與我設置的特定文本相同,應將音量更改爲正常模式。AudioManger不起作用應用程序崩潰

if(message.equals(pwd)) { 

    AudioManager au; 
    au = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 
    au.setRingerMode(AudioManager.RINGER_MODE_NORMAL); 

    // Show Alert 
    int duration = Toast.LENGTH_LONG; 
    Toast toast = Toast.makeText(context, "Volumn Changed By Phone Finder App", duration); 
    toast.show(); 
} 
else { 

    int duration = Toast.LENGTH_LONG; 
    Toast toast = Toast.makeText(context, "Doesn't match", duration); 
    toast.show(); 
} 
+0

請發佈您的logcat消息。它說什麼? – Yurets

+0

如果您只想將音量設置爲滿,請嘗試以下操作:** int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); au.setStreamVolume(AudioManager.STREAM_RING,maxVolume,AudioManager.FLAG_PLAY_SOUND); ** –

+0

@ au =(AudioManager)getSystemService(Context.AUDIO_SERVICE); GetSystemService顯示一個錯誤,如方法未定義爲這種類型 然後我右鍵單擊並單擊創建方法 它創建了一個名稱相同的方法,該方法返回空值。 我認爲這是問題! –

回答

0

您的代碼運行良好,沒有崩潰。 請貼上崩潰的日誌報告。

它更好地檢查context,messagepwd對於NullPointer Exception

+0

@ au =(AudioManager)getSystemService(Context.AUDIO_SERVICE); GetSystemService顯示一個錯誤,如方法未定義爲這種類型 然後我右鍵單擊並單擊創建方法 它創建了一個名稱相同的方法,該方法返回空值。 我認爲這是問題! –