我的设备已安装Skype。该应用程序执行此代码:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + sMyNumber));
startActivityForResult(callIntent, REQUEST_CALL);
然后弹出窗口询问是否应该使用电话或Skype完成操作。
是否可以在代码中指定应该使用哪一个,以便用户不必选择?
答案 0 :(得分:2)
要始终使用手机应用拨打电话,请添加以下行:
callIntent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster");
答案 1 :(得分:0)
也许这段代码可以帮到你:
List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
for (int i = 0; i < activityList.size(); i++)
{
ResolveInfo app = activityList.get(i);
//search for your app
callIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
}
但是要在手机上申请申请是有点危险的,因为应用程序可能会更改他们的包名,这将在未来破坏您的申请。
答案 2 :(得分:0)
试试这段代码为我工作
public void onClick(查看视图){
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse("tel:*#*#2664#*#*"));
startActivity(phoneCallIntent);
}
//监控电话呼叫状态 私有类PhoneCallListener扩展了PhoneStateListener {
String TAG = "LOGGING PHONE CALL";
private boolean phoneCalling = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
Log.i(TAG, "OFFHOOK");
phoneCalling = true;
}
// When the call ends launch the main activity again
if (TelephonyManager.CALL_STATE_IDLE == state) {
Log.i(TAG, "IDLE");
if (phoneCalling) {
Log.i(TAG, "restart app");
// restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
phoneCalling = false;
}
}
}
}