从Build tool 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)显示的错误是
调用需要可能被用户拒绝的权限:代码应显式检查权限是否可用(使用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); }究竟调用startActiivty方法所需的条件是什么? 如果可能,请提供可能导致相同类型错误的其他权限的详细信息。
After switching from Build tool 22.0 to 23.1 i am getting error in start activity method.
Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callIntent);The error displaying in line startActivity(callIntent)is
Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
The same error was displaying for Location and Content resolver. I solved it by checking condition like
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); }What exactly the condition which is required in order to call startActiivty method ? Please provide the details if possible for other permissions which may cause same type of errors.
最满意答案
调用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_CALL意图,这需要一个权限,即android.permission.CALL_PHONE 。
通常你会把它放在你的清单中
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>但是使用api 23+,您必须检查权限运行时,与您对位置所做的相同:
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); }What exactly the condition which is required in order to call startActivity method?
Your code
Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callIntent);Uses the Intent.ACTION_CALL intent, which requires a permission, namely the android.permission.CALL_PHONE one.
Normally you would put this in your manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>but with api 23+ you have to check for permissions runtime, same as you did with the location:
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); }活动意图权限Android M SDK 23(Activity Intent Permission Android M SDK 23)从Build tool 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)显示的错误是
调用需要可能被用户拒绝的权限:代码应显式检查权限是否可用(使用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); }究竟调用startActiivty方法所需的条件是什么? 如果可能,请提供可能导致相同类型错误的其他权限的详细信息。
After switching from Build tool 22.0 to 23.1 i am getting error in start activity method.
Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callIntent);The error displaying in line startActivity(callIntent)is
Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
The same error was displaying for Location and Content resolver. I solved it by checking condition like
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); }What exactly the condition which is required in order to call startActiivty method ? Please provide the details if possible for other permissions which may cause same type of errors.
最满意答案
调用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_CALL意图,这需要一个权限,即android.permission.CALL_PHONE 。
通常你会把它放在你的清单中
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>但是使用api 23+,您必须检查权限运行时,与您对位置所做的相同:
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); }What exactly the condition which is required in order to call startActivity method?
Your code
Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(callIntent);Uses the Intent.ACTION_CALL intent, which requires a permission, namely the android.permission.CALL_PHONE one.
Normally you would put this in your manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>but with api 23+ you have to check for permissions runtime, same as you did with the location:
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); }
发布评论