我想通過我的應用程序通過放置額外的數據打電話,但在通話過程中我無法接收該數據可以解釋下面我錯了什麼是我的撥打電話的代碼和接收呼叫android add extra and call programmatically
String uri = "tel:"+my_name;
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
callIntent.putExtra("data", "mynewdata");
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) {
showToast(intent.getExtras().getString("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());
}
}
}
我收到呼叫完美,甚至廣播工作完美,但我從沒有意圖獲取數據「intent.getExtras()。getBoolean(」數據「)」
其實你的數據傳遞給Intent.ACTION_CALL問題並且只能使用getIntent()在Intent.ACTION_CALL中獲取數據。您收到的廣播是針對其他一些不包含您提供的意圖數據的線程。你在廣播中的意圖與你傳遞的意圖不同。您需要以其他方式傳遞數據。 –
嘗試像這樣'Bundle bundle = intent.getBundleExtra(「data」);' – Vijay
或'intent.getStringExtra(「data」));' – Vijay