2013年9月22日星期日

android ringing delay implementation problems encountered ( 100 for help )

Members : I would like to achieve is when the phone call delay 10 seconds and then ring + vibration , the following is my code , the result is 10 seconds after the shock , but it did not ring to ask what might 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: my radio and permissions are listed below:

  <receiver android:name=".PhoneReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                <action android:name="android.intent.action.TIME_SET" />
                <action android:name="android.intent.action.TIME_TICK" />
                <action android:name="android.intent.action.TIMEZONE_CHANGED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>

    <uses-permission android:name="android.permission.READ_PHONE_STATE" >
    </uses-permission>
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" >
    </uses-permission>
    <uses-permission android:name="android.permission.RECEIVE_SMS" >
    </uses-permission>
    <uses-permission android:name="android.permission.VIBRATE" >
    </uses-permission>
     <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" >
    </uses-permission>

------ Solution ------------------------------------- -------
solution is: you obtain the original ringtone file path, and then create your own code to play the file.
------ Solution ---------------------------------------- ----
this is a system beep playback unit , if you want to play a ring tone , 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 ();
}
}
------ eference ----------------------------------- ----
ask a question of your ring is what triggers
If yes telephony layer up the CRING
10 seconds later the phone should automatically hang up
------ eference --------------------- ------------------

Bell trigger ? I direct the AudioManager tm = (AudioManager) context.getSystemService (Context.AUDIO_SERVICE);
tm.setRingerMode (AudioManager.RINGER_MODE_NORMAL);
Do not do it ?
------ eference --------------------------------------- < br> heroes wing ah
------ eference -------------------------------- -------
go top . . . .
------ eference --------------------------------------- < br> for Notification look , :-)
------ eference ------------------------------ ---------

Why ?
------ eference --------------------------------------- < br> ringing tone playback mechanism should be something like this:

determine whether the current volume is muted or set to 0, if 0, no play, program play ringtones directly over.

So , no matter how you change the code behind the ring are of no use.
------ eference --------------------------------------- < br>
you mean , technically speaking, this is simply impossible to achieve it ?
------ eference --------------------------------------- < br>
incoming call , the phone software like housekeeper , had this feature it , those who hung the phone ring for several seconds is not the first ring , that is, to achieve a delay rings function ah
------ eference -------------------------------------- -
  This reply was moderator deleted at 2012-05-28 08:45:37

------ eference ------------------------------------ ---

me think of a go. Get original ringtones, you can achieve it ?
------ eference --------------------------------------- < br>
how to obtain the phone to set a good tone it ? Including ringtones and notification tones ?
------ eference --------------------------------------- < br> ask the landlord , is how to achieve , I tried your code, vibration and ring do not delay , do not know the landlord has not solved the problem , neighborhoods
------ eference --- ------------------------------------
remove setStreamVolume methods , this does not matter, I wrote it myself the ok the

没有评论:

发表评论