문제

I have an app that starts a notification at a certain time, the user can choose the ringtone of the notification, when I put my phone on mute mode and the screen was off the notification didn't vibrate but when the screen was on it vibrated even when I had a phone call, when I changed the phone mode to sound and had a phone call the notification didn't make a sound but vibrated although I'm having a phone call how to fix that? What I mean is: is this a normal thing because it's normal I think that I have to check for the phone state and if it was ringing I have to change the notification's vibration to off... because it's my first app and need to know what should I have to do for a notification to not cause any troubles... thanks.

도움이 되었습니까?

해결책

Waht I've done:

                listener = new PhoneStateListener() {
                @Override
                public void onCallStateChanged(int state, String incomingNumber) {
                    switch (state) {
                    case TelephonyManager.CALL_STATE_IDLE:
                        stateString = "Idle";
                        break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                        stateString = "Off Hook";                   
                        break;
                    case TelephonyManager.CALL_STATE_RINGING:
                        stateString = "Ringing";                    
                        break;
                    }
                    create_notification(notif_title,notif_body);

                }
            };
            telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

            AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            switch( audio.getRingerMode() ){
            case AudioManager.RINGER_MODE_NORMAL:
            modeString="normal";
               break;
            case AudioManager.RINGER_MODE_SILENT:
                modeString="silent";
               break;
            case AudioManager.RINGER_MODE_VIBRATE:
                modeString="vibrate";
               break;
            }



if(bool_activate_vibrate==true && stateString=="Idle" && modeString!="silent"){
            Vibrator v = (Vibrator) c.getSystemService       (Context.VIBRATOR_SERVICE);                
            v.vibrate(2000);
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top