1

我正在开发一个应用程序,当某些事件发生时,我必须将我的电话状态更改为响铃,例如某个号码正在我的电话上呼叫。那可能吗?我对广播接收器有一些想法,它将事件广播到我的应用程序,然后我的应用程序将在我的手机上发出任何虚拟的假号码呼叫。请给我任何想法。可能吗?以及如何开始?

任何帮助表示赞赏。谢谢!

4

3 回答 3

1

要更改为响铃,请使用 TelephonyManager、AudioManager 和 PhoneStateListener:

{
  // USE AudioManager  for Settingringing from vibration
         AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);   

         switch (am.getRingerMode()) {   
                 case AudioManager.RINGER_MODE_VIBRATE:   
                 Log.i("MyApp","NORMAL mode");
                 am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
              break;   
            }     
于 2012-12-07T06:52:19.793 回答
0

尝试这样的事情

public class Telephone extends BroadcastReceiver {

    private Context mContext;
    private Intent mIntent;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        mIntent = intent;
        TelephonyManager tm = (TelephonyManager)              
                 context.getSystemService(Context.TELEPHONY_SERVICE);
        int events = PhoneStateListener.LISTEN_CALL_STATE;
        tm.listen(phoneStateListener, events);
    }

    private final PhoneStateListener phoneStateListener = 
                                                new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            String callState = "UNKNOWN";
            switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:

                break;
            case TelephonyManager.CALL_STATE_RINGING:
                                // DO YOUR WORK HERE

                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                          if(incomingNumber.length() >0){

                                  // incoming call
                                 // DO YOUR WORK HERE when call is received
                                 // SEND SMS HERE
                            }
                           else{
                                      // outgoing call
                              }
                break;
            }

            super.onCallStateChanged(state, incomingNumber);
        }
    };

}

您需要注册一个 PhoneStateListener.LISTEN_CALL_STATE 仅用于接收

BroadcastReceiver 内的来电。

于 2012-12-07T06:48:55.707 回答
0

您可以添加此代码以在触发某些事件时进行调用。

      String Numb = "tel:" + "your number";
      Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(Numb));
      startActivity(intent);

并为此向您的清单添加权限。

       <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
于 2012-12-07T06:45:28.150 回答