活动意图权限Android M SDK 23
从构建工具22.0切换到23.1后,我在启动活动方法中遇到错误活动意图权限Android M SDK 23,android,android-intent,android-permissions,Android,Android Intent,Android Permissions,从构建工具22.0切换到23.1后,我在启动活动方法中遇到错误 Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callIntent); 在startActivity(callIntent)行中显示的错误
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
在startActivity(callIntent)
行中显示的错误为
调用需要用户可能拒绝的权限:代码应为
明确检查权限是否可用(使用
checkPermission
)或显式处理潜在的
SecurityException
位置和内容解析程序显示相同的错误。
我通过检查以下条件来解决它
if (mContext.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| mContext.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
location = LocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
调用StartActivity方法所需的具体条件是什么?
如果可能,请提供可能导致相同类型错误的其他权限的详细信息
调用startActivity方法所需的具体条件是什么
你的代码
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
使用Intent.ACTION\u CALL
Intent,它需要权限,即android.permission.CALL\u手机
one
通常你会把这个放在你的舱单上
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
查看此演示谢谢Tim。很好用。我有一个疑问。用户将在何处向应用授予权限?如果上面的代码是在后台服务中编写的,那么对话框将如何显示为这样,谢谢您的时间:)
if (mContext.checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
}