Thursday, April 17, 2014

android ringing delay implementation issues encountered (100 for help)


Members: I want to achieve is to delay 10 seconds when the phone calls ring + vibrate again, here is my code, the result is 10 seconds after the shock, but no rings, ask what could be the reason?


 
public class PhoneReceiver extends BroadcastReceiver implements Runnable {
private Handler handler;
private Context context;
private Vibrator mVibrator01;

@ Override
public void onReceive (Context context, Intent intent) {
this.context = context;
/ / If call others, do nothing
if (intent.getAction (). equals (Intent.ACTION_NEW_OUTGOING_CALL)) {

}
/ / If be called
else {
AudioManager am = (AudioManager) context.getSystemService (Context.AUDIO_SERVICE);
int mode = am.getRingerMode ();
if (mode! = AudioManager.RINGER_MODE_SILENT) {
am.setStreamVolume (AudioManager.STREAM_RING, 0, 0);
}
handler = new Handler ();
handler.postDelayed (this, 10000);
}
}
@ Override
public void run () {
AudioManager tm = (AudioManager) context.getSystemService (Context.AUDIO_SERVICE);
tm.setRingerMode (AudioManager.RINGER_MODE_NORMAL);
tm.setStreamVolume (AudioManager.STREAM_RING, 5, 0);
mVibrator01 = (Vibrator) context.getSystemService (Service.VIBRATOR_SERVICE);
mVibrator01.vibrate (10000);
}

}

PS: I broadcast and permissions are listed below:
 






















<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Ask a question of your ring used to trigger what
If the telephony layer up the CRING
After 10 seconds the phone should automatically hang up
Reply:
cited a floor reply:
ask a question of your ring used to trigger what
If the telephony layer up the CRING
After 10 seconds the phone should automatically hang up

Bell Trigger? AudioManager tm me directly used = (AudioManager) context.getSystemService (Context.AUDIO_SERVICE);
tm.setRingerMode (AudioManager.RINGER_MODE_NORMAL);
Do not do it?
Reply:
Heroes wing ah
Reply:
Go to the top. . . .
Reply:
Conversion Notification look :-)
Reply:
references, 5th Floor reply:
change Notification look, :-)

Why?
Reply:
Ringtone playback mechanism should be like this:

Determine whether the current settings, or mute the volume to 0, if it is 0, no play, program play ringtones directly over.

Therefore, no matter how you change the code behind ringtones are of no use.
Reply:
reference to the 7th floor of replies:
ringtone playback mechanism should be like this:

Determine whether the current settings, or mute the volume to 0, if it is 0, no play, program play ringtones directly over.

Therefore, no matter how you change the code behind ringtones are of no use.

You mean, technically speaking, this is simply impossible to achieve it?
Reply:
reference to the 7th floor of replies:
ringtone playback mechanism should be like this:

Determine whether the current settings, or mute the volume to 0, if it is 0, no play, program play ringtones directly over.

Therefore, no matter how you change the code behind ringtones are of no use.

Incoming call, the phone software like housekeeper, there is such a feature of it, those who hung the phone rang several more seconds is not the first ring, which is to achieve a delayed ringing function ah
Reply:
The reply was deleted at the moderator 2012-05-28 08:45:37

Reply:
The solution is: get the path of the original ringtone file in advance, and then create a code to play the files themselves.
Reply:
reference to the 11th floor of the reply:
solution is: ringing in advance to get the path of the original file, and then create the code to play the files themselves.

And I think one go. Get the original ringtones that can be achieved?
Reply:
reference to the 11th floor of the reply:
solution is: ringing in advance to get the path of the original file, and then create the code to play the files themselves.

How to get the phone to set a good tone it? Including ringtones and notification tones?
Reply:
This is the tone of the playback system unit, if you want to play ringtones, the TYPE_NOTIFICATION into TYPE_ALARM
private void PlayAlarmRing () {
Uri alert = RingtoneManager
. GetDefaultUri (RingtoneManager.TYPE_NOTIFICATION);
try {
MediaPlayer mMediaPlayer = new MediaPlayer ();
mMediaPlayer.setDataSource (this, alert);
final AudioManager audioManager = (AudioManager) getSystemService (Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume (AudioManager.STREAM_ALARM)! = 0) {
mMediaPlayer.setAudioStreamType (AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping (false);
mMediaPlayer.prepare ();
mMediaPlayer.start ();
}
} Catch (IllegalStateException e) {
e.printStackTrace ();
} Catch (IOException e) {
e.printStackTrace ();
}
}
Reply:
Ask the landlord, is how to achieve, after I tried your code, vibration and ring do not delay, do not know if the landlord has not solved the problem, ask for advice
Reply:
Remove setStreamVolume method, and this does not matter, ok, I wrote it myself

No comments:

Post a Comment