2012-08-13 1 views
0

WhatsApp는 백그라운드에서 실행할 때 항상 볼륨을 높게 알려주고 내 연락처 (사용자 지정 알림 소리가있는 사용자) 중 하나가 나타납니다.비 스트리밍 환경 설정에 대한 알림 용 BroadcastReceiver의 출력 볼륨을 변경하십시오.

비슷한 효과를 얻으려고합니다. 알림 볼륨을 제어하고 싶습니다. 내가 스택 오버플로에서 찾을 수

유일한 예는 여기 this.

의 차이라고 있습니다

  1. 내 상황이 BroadcastReceiver
  2. 내가 음악을 스트리밍하지만 기반 알림 음을 사용하지 않는 오전 전화에서 사용할 수있는 기본 벨소리 목록 (WhatsApp와 유사).

알림 관리자는 getSystemService(Context.NOTIFICATION_SERVICE)을 기반으로하므로 스트리밍에 일반적으로 사용 가능한 일부 방법을 사용할 수없는 것으로 보입니다.

빛을 비추는 사람이 있습니까? 코드 :

public class OnAlarmReceiver extends BroadcastReceiver { 
private static final int NOTIFY_ME_ID=1337; 

private static final String TAG = "OnAlarmReceiver"; 

@Override 
public void onReceive(Context ctxt, Intent intent) {  
    Bundle bundle = intent.getExtras(); 
    int itemId = bundle.getInt("itemId"); 
    String itemTitle = bundle.getString("itemTitle"); 
    int priority = bundle.getInt("priority"); 
    long listId = bundle.getLong("listId"); 
    String listTitle = bundle.getString("listTitle"); 

    Toast.makeText(ctxt, "itemId: " + Integer.toString(itemId), Toast.LENGTH_LONG).show(); 

    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(ctxt); 
    boolean useNotification=prefs.getBoolean("use_notification", true); 

    if (useNotification) { 
     NotificationManager mgr = (NotificationManager)ctxt.getSystemService(Context.NOTIFICATION_SERVICE);         
     Notification notification = new Notification();   
     if (priority == 1) { // Display red icon 
      notification=new Notification(R.drawable.nuvola_apps_kwrite, itemTitle, System.currentTimeMillis());  
     } else { // Display blue icon 
      notification=new Notification(R.drawable.nuvola_apps_package_editors, itemTitle, System.currentTimeMillis());    
     }   
     Intent itemEditor = new Intent(ctxt, EditItem.class); 
     long lAlarmId = (long) (int) itemId; 
     itemEditor.putExtra(DbAdapter.KEY_ITEMS_ITEM_ID, lAlarmId); 
     itemEditor.putExtra("listId", listId); 
     itemEditor.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

     PendingIntent i=PendingIntent.getActivity(ctxt, 0, itemEditor, PendingIntent.FLAG_UPDATE_CURRENT);   
     notification.setLatestEventInfo(ctxt, listTitle, itemTitle, i);   
     String notifyPreference = prefs.getString("notification_sound", "DEFAULT_RINGTONE_URI");       
     notification.sound = Uri.parse(notifyPreference); 

     if (priority == 1) { 
      notification.defaults |= Notification.DEFAULT_VIBRATE; 
     }   
     mgr.notify(itemId + NOTIFY_ME_ID, notification); 
    } 
    else { 
     Intent i=new Intent(ctxt, AlarmActivity.class); 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     ctxt.startActivity(i); 
    } 
} 

}

답변

0

흠, 당신이 시도 했습니까? (네, 오디오 스트림을 사용하지만 작동 할 것입니다)

private AudioManager mAudioManager; 
private Context ctxt; 

mAudioManager = (AudioManager)ctxt.getSystemService(Context.AUDIO_SERVICE); 

int streamVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); 

mAudioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, streamVolume, 0); 
+0

고마워요! –

+0

당신은 환영합니다 :) –

관련 문제