1

電話がサイレントモードであっても、特定の連絡先が鳴るようにしようとしています。アプリをインストールした後に最初の電話がかかってきたとき、電話は鳴っていませんが、それ以降は完全に機能しています...コードに問題はありますか...

      package com.cnu.incoming;


      import android.app.PendingIntent;
      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.hardware.Sensor;
      import android.hardware.SensorEvent;
      import android.hardware.SensorEventListener;
      import android.hardware.SensorManager;
      import android.media.AudioManager;
      import android.os.Bundle;
      import android.telephony.SmsManager;
      import android.telephony.TelephonyManager;
      import android.util.Log;
      import android.widget.Toast;

      public class IncomingCall extends BroadcastReceiver{


      private Context context;
      private String PhNumber;
      private int ringcheck=0;
      String state=null;
      Bundle bundle=null;



@Override
public void onReceive(Context context, Intent intent) {
     AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
        bundle = intent.getExtras();
        this.context = context;


        if(null == bundle)
                return;

        Log.i("IncomingCallReceiver",bundle.toString());

        state = bundle.getString(TelephonyManager.EXTRA_STATE);

        Log.i("IncomingCallReceiver","State: "+ state);

        if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
        {
                check();
                if(PhNumber.equals("+919876543210"))
                makeitNormal();
                PhNumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

                Log.i("IncomingCallReceiver","Incomng Number: " + PhNumber);

                String info = "Detect Calls Incoming number: " + PhNumber;


                maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);


        }

        Log.i("baddu gadu" ,"baddu gadu");

        if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK))
        {
            makeItSilent();
        }

        if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE))
        {
            makeItSilent();
        }


}



private void check() {
    // TODO Auto-generated method stub
    AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
    ringcheck=maudio.getRingerMode();

}

private void makeitNormal() {
    // TODO Auto-generated method stub

    AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
    maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    //Toast.makeText(context, "this is baradwaj", Toast.LENGTH_LONG).show();

}


private void makeItSilent() {
    // TODO Auto-generated method stub
    AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
    int ringer=maudio.getRingerMode();
    if (ringcheck==AudioManager.RINGER_MODE_SILENT){

        maudio.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    }else if(ringcheck==AudioManager.RINGER_MODE_NORMAL){
        maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }
    else if(ringcheck==AudioManager.RINGER_MODE_VIBRATE){
        maudio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    }

}

public void onAccuracyChanged(Sensor arg0, int arg1) {
    // TODO Auto-generated method stub

}

public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub


}

}

4

0 に答える 0