Android中如何向Google Duo传递电话号码数据?
解决Android中向Google Duo传递电话号码并启动通话的问题
嘿,你的思路方向是对的,但问题出在用getLaunchIntentForPackage()获取的主入口Intent并不支持直接接收tel:格式的URI数据——Google Duo的主Activity不会处理这类传入的数据,所以才会失效。下面给你两种可行的解决方案:
方法一:强制让Duo处理标准电话URI
这种方法利用系统的ACTION_VIEW动作,指定由Duo来处理电话号码的呼叫请求,代码如下:
String phoneNumber = "你的目标电话号码"; Uri callUri = Uri.parse("tel:" + phoneNumber); Intent duoIntent = new Intent(Intent.ACTION_VIEW, callUri); // 指定仅由Google Duo处理该Intent duoIntent.setPackage("com.google.android.apps.tachyon"); try { startActivity(duoIntent); } catch (ActivityNotFoundException e) { // 处理用户未安装Duo的情况,比如提示下载 Toast.makeText(this, "请先安装Google Duo应用", Toast.LENGTH_SHORT).show(); }
方法二:使用Duo的自定义深链URI
Google Duo支持自定义的duo://协议,可以直接唤起通话界面,代码更简洁:
String phoneNumber = "你的目标电话号码"; Uri duoCallUri = Uri.parse("duo://call/" + phoneNumber); Intent duoIntent = new Intent(Intent.ACTION_VIEW, duoCallUri); try { startActivity(duoIntent); } catch (ActivityNotFoundException e) { Toast.makeText(this, "请先安装Google Duo应用", Toast.LENGTH_SHORT).show(); }
注意事项
- 两种方法都需要处理
ActivityNotFoundException,避免用户未安装Duo时崩溃。 - 不需要额外申请
CALL_PHONE权限,因为我们只是唤起Duo的界面,实际通话操作由Duo自身处理。
内容的提问来源于stack exchange,提问作者humni
相关产品推荐
相关产品推荐

