Android : 打电话和发短信的Intent需要加权限吗?
Android : For call and send SMS Intent need to add permission?
我正在处理用户点击通话和短信按钮时的通话和短信意图。
问题:
1) 需要在 AndroidManifest.xml
文件中添加权限?
2) 还需要为运行时权限编写代码吗?
我为 call intent 编写的代码如下:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + driverMobileNo));
startActivity(intent);
短信意图
Intent it = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+ driverMobileNo));
it.putExtra("sms_body", "The SMS text");
startActivity(it);
以上代码工作正常(在 Oreo 8.0 版本中测试),无需在 AndroidManifest.xml 和运行时添加权限。
您可以在未经任何许可的情况下使用此代码:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent);
对于通话,您可以在未经任何许可的情况下使用:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:phoneNumber"))
startActivity(intent);
您不需要任何权限,因为用户实际拨打电话,您只需将他重定向到 phone 应用程序。如果您想直接通过您的应用程序调用 phone,您必须使用 ACTION_CALL
而不是 ACTION_DIAL
并添加权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
希望对您有所帮助!
对于短信你可以写
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:"+phoneNumber)); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
startActivity(intent);
对于通话,您可以使用此 intent
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
我正在处理用户点击通话和短信按钮时的通话和短信意图。
问题:
1) 需要在 AndroidManifest.xml
文件中添加权限?
2) 还需要为运行时权限编写代码吗?
我为 call intent 编写的代码如下:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + driverMobileNo));
startActivity(intent);
短信意图
Intent it = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+ driverMobileNo));
it.putExtra("sms_body", "The SMS text");
startActivity(it);
以上代码工作正常(在 Oreo 8.0 版本中测试),无需在 AndroidManifest.xml 和运行时添加权限。
您可以在未经任何许可的情况下使用此代码:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent);
对于通话,您可以在未经任何许可的情况下使用:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:phoneNumber"))
startActivity(intent);
您不需要任何权限,因为用户实际拨打电话,您只需将他重定向到 phone 应用程序。如果您想直接通过您的应用程序调用 phone,您必须使用 ACTION_CALL
而不是 ACTION_DIAL
并添加权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
希望对您有所帮助!
对于短信你可以写
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:"+phoneNumber)); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
startActivity(intent);
对于通话,您可以使用此 intent
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);