簡體   English   中英

我可以將數據發送到Intent.ACTION_CALL嗎?

[英]Can i send data to Intent.ACTION_CALL?

我是一名新的android開發人員。 我可以將數據發送到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);

接收器的動作是android.intent.action.PHONE_STATE。 如何在BroadcastReceiver的onReceive()中獲取標志值?

請幫幫我。

試試這個創建一個類

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

現在創建一個這樣的意圖

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());
    }
      }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM