我如何在电话 phone 通话中以编程方式在 phone 拨号器屏幕中设置号码?
How can i set number in phone dialer screen programatically while in telephone call?
我试图在电话 phone 调用 Android 时以编程方式设置 phone 拨号器的号码,但我暂时找不到解决方案。
我正在使用此代码设置 phone 拨号器并在用户拨打给定号码时呼叫:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:04445556677"));
startActivity(intent);
此外,我可以在空闲时使用 ACTION_DIAL 而不是 ACTION_CALL 来设置 phone 拨号器,我可以用它设置 phone 拨号器,但我可以在 phone 通话中未设置 phone 拨号器。
此外,这是我的接听电话class:
public class CallReceiver extends BroadcastReceiver {
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static Date callStartTime;
private static boolean isIncoming;
private static String savedNumber;
@Override
public void onReceive(Context context, Intent intent) {
//Log.w("intent " , intent.getAction().toString());
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");//buda çekiyor sanırsam
} else {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);//tel numarasını çekiyor
int state = 0;
if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
state = TelephonyManager.CALL_STATE_IDLE;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
onCallStateChanged(context, state, number);
}
}
public void onCallStateChanged(Context context, int state, String number) {
if (lastState == state) {
//No change, debounce extras
return;
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
isIncoming = true;
callStartTime = new Date();
savedNumber = number;
Toast.makeText(context, "Incoming Call Ringing", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if (lastState != TelephonyManager.CALL_STATE_RINGING) {
isIncoming = false;
callStartTime = new Date();
Toast.makeText(context, "Outgoing Call Started", Toast.LENGTH_SHORT).show();
}
break;
case TelephonyManager.CALL_STATE_IDLE:
//Went to idle- this is the end of a call. What type depends on previous state(s)
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
//Ring but no pickup- a miss
Toast.makeText(context, "Ringing but no pickup" + savedNumber + " Call time " + callStartTime + " Date " + new Date(), Toast.LENGTH_SHORT).show();
} else if (isIncoming) {
Toast.makeText(context, "Incoming " + savedNumber + " Call time " + callStartTime, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "outgoing " + savedNumber + " Call time " + callStartTime + " Date " + new Date(), Toast.LENGTH_SHORT).show();
}
break;
}
lastState = state;
}
}
我希望有人能帮助我。提前致谢。
您混淆了两个非常相似但仍然非常不同的活动:
Phone
的拨号器 - 允许用户拨打一些 phone 号码
InCallUi
的拨号器 - 允许用户在通话期间发送按键音以导航菜单。
第一个设置为接收 ACTION_CALL
/ ACTION_DIAL
意图,第二个没有设置广播意图,因此您无法操纵它。
我试图在电话 phone 调用 Android 时以编程方式设置 phone 拨号器的号码,但我暂时找不到解决方案。
我正在使用此代码设置 phone 拨号器并在用户拨打给定号码时呼叫:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:04445556677"));
startActivity(intent);
此外,我可以在空闲时使用 ACTION_DIAL 而不是 ACTION_CALL 来设置 phone 拨号器,我可以用它设置 phone 拨号器,但我可以在 phone 通话中未设置 phone 拨号器。
此外,这是我的接听电话class:
public class CallReceiver extends BroadcastReceiver {
private static int lastState = TelephonyManager.CALL_STATE_IDLE;
private static Date callStartTime;
private static boolean isIncoming;
private static String savedNumber;
@Override
public void onReceive(Context context, Intent intent) {
//Log.w("intent " , intent.getAction().toString());
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");//buda çekiyor sanırsam
} else {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);//tel numarasını çekiyor
int state = 0;
if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
state = TelephonyManager.CALL_STATE_IDLE;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
state = TelephonyManager.CALL_STATE_OFFHOOK;
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}
onCallStateChanged(context, state, number);
}
}
public void onCallStateChanged(Context context, int state, String number) {
if (lastState == state) {
//No change, debounce extras
return;
}
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
isIncoming = true;
callStartTime = new Date();
savedNumber = number;
Toast.makeText(context, "Incoming Call Ringing", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if (lastState != TelephonyManager.CALL_STATE_RINGING) {
isIncoming = false;
callStartTime = new Date();
Toast.makeText(context, "Outgoing Call Started", Toast.LENGTH_SHORT).show();
}
break;
case TelephonyManager.CALL_STATE_IDLE:
//Went to idle- this is the end of a call. What type depends on previous state(s)
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
//Ring but no pickup- a miss
Toast.makeText(context, "Ringing but no pickup" + savedNumber + " Call time " + callStartTime + " Date " + new Date(), Toast.LENGTH_SHORT).show();
} else if (isIncoming) {
Toast.makeText(context, "Incoming " + savedNumber + " Call time " + callStartTime, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "outgoing " + savedNumber + " Call time " + callStartTime + " Date " + new Date(), Toast.LENGTH_SHORT).show();
}
break;
}
lastState = state;
}
}
我希望有人能帮助我。提前致谢。
您混淆了两个非常相似但仍然非常不同的活动:
Phone
的拨号器 - 允许用户拨打一些 phone 号码InCallUi
的拨号器 - 允许用户在通话期间发送按键音以导航菜单。
第一个设置为接收 ACTION_CALL
/ ACTION_DIAL
意图,第二个没有设置广播意图,因此您无法操纵它。