恢复 phone 调用 UI
Recover phone call UI
基本上我想通过我的 activities
.
中的一个按钮开始当前的 phone 调用 ui
到目前为止,我已经能够使用
开始新的通话
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000000"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
或移动到 phone本书使用:
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
我也尝试过使用该代码,但它似乎不适用于 HTC 设备和某些华为设备(ri
是 null
)。
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage("com.android.phone");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
我想要的是直接转到通话 ui。行为与此过程中的行为相同:
- 正在phone通话中
- 返回主屏幕
- 展开通知栏
- 点击通话行
我不知道如何实现以及如何使其适用于所有设备。
感谢您宝贵的帮助。
你必须按照这个答案的建议去做:android.permission.CALL_PHONE for tablets
添加调用phone权限:
<uses-permission android:name="android.permission.CALL_PHONE"/>
然后调用 Intent.ACTION_CALL
.
Intent intentcall = new Intent(
Intent.ACTION_CALL,
Uri.parse("tel:" + phonenumber));
startActivity(intentcall);
编辑:
有一种方法可以实现,但它在 Lollipop 及以后的版本中不起作用,因为出于安全原因它已被弃用。
您可以使用 ActivityManager
到 get the running tasks and then analyse the content of each RunningTaskInfo to determine which one is the "phone" and then use the task ID to call moveTaskToFront。它可能有效,但正如我所说,它不适用于 Lollipop 和未来版本。
基本上我想通过我的 activities
.
到目前为止,我已经能够使用
开始新的通话Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000000"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
或移动到 phone本书使用:
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
我也尝试过使用该代码,但它似乎不适用于 HTC 设备和某些华为设备(ri
是 null
)。
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage("com.android.phone");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
我想要的是直接转到通话 ui。行为与此过程中的行为相同:
- 正在phone通话中
- 返回主屏幕
- 展开通知栏
- 点击通话行
我不知道如何实现以及如何使其适用于所有设备。
感谢您宝贵的帮助。
你必须按照这个答案的建议去做:android.permission.CALL_PHONE for tablets
添加调用phone权限:
<uses-permission android:name="android.permission.CALL_PHONE"/>
然后调用 Intent.ACTION_CALL
.
Intent intentcall = new Intent(
Intent.ACTION_CALL,
Uri.parse("tel:" + phonenumber));
startActivity(intentcall);
编辑:
有一种方法可以实现,但它在 Lollipop 及以后的版本中不起作用,因为出于安全原因它已被弃用。
您可以使用 ActivityManager
到 get the running tasks and then analyse the content of each RunningTaskInfo to determine which one is the "phone" and then use the task ID to call moveTaskToFront。它可能有效,但正如我所说,它不适用于 Lollipop 和未来版本。