【问题标题】:Can i send data to Intent.ACTION_CALL?我可以将数据发送到 Intent.ACTION_CALL 吗?
【发布时间】:2017-06-22 06:47:55
【问题描述】:

我是一名新的安卓开发者。我可以将数据发送到 Intent.ACTION_CALL 吗? 我的代码在下面

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phone_number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.putExtra("flag",1);
context.startActivity(callIntent);

Receiver的动作是android.intent.action.PHONE_STATE。如何在 BroadcastReceiver 的 onReceive() 中获取标志值?

请帮帮我。

【问题讨论】:

  • 请检查我的回答@manjari

标签: android android-intent broadcastreceiver intentfilter


【解决方案1】:

试试这个创建一个类

 public class example
{
 public static boolean data;
 public static String strData = "";
}

现在创建一个这样的 Intent

String uri = "tel:"+my_name;
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
    example.data = true; /*see change, set data in Constants.data*/
    example.str = "Hello world..."; /*see change*/
    callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    _context.startActivity(callIntent);

现在在广播接收器中查看所做的更改...

public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    final Bundle bundle = intent.getExtras();
    if(bundle != null && example.data) { /*changes done, get boolean from the Constants.data*/
        Log.e("hi i have recieve",example.str);//print recieved data
    } 

    if (intent.getAction().equals("android.intent.action.PHONE_STATE")) { 
        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        Log.d(TAG,"PhoneStateReceiver**Call State=" + state);
        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
            if(recieveCall){

            }
            Log.d(TAG,"PhoneStateReceiver**Idle");
        } else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 

        } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
        }
    } else if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { 
        // Outgoing call
        String outgoingNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Log.d(TAG,"PhoneStateReceiver **Outgoing call " + outgoingNumber);

        setResultData(null); // Kills the outgoing call

    } else {
        Log.d(TAG,"PhoneStateReceiver **unexpected intent.action=" + intent.getAction());
    }
      }
}

【讨论】:

  • 我试过了,它会得到 Log.e("hi i have recieve",example.str);所有拨出电话
猜你喜欢
  • 1970-01-01
  • 2021-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多