我面临一个奇怪的问题。我遵循本教程是为了在运行时为我构建的应用程序请求权限。问题是,即使我检查设备是否使用 Android M 并且我在运行时请求权限,它也不会显示对话框。
编码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configuration);
spinner = (Spinner)findViewById(R.id.database_selection_spinner);
button = (Button)findViewById(R.id.proceedBtn);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(ConfigurationActivity.this, Manifest.permission.INTERNET) == PackageManager.PERMISSION_GRANTED){
accessWebService();
}else {
if (shouldShowRequestPermissionRationale(Manifest.permission.INTERNET)){
StringGenerator.showToast(ConfigurationActivity.this, "Internet Permission needs to be granted");
}
requestPermissions(new String[]{Manifest.permission.INTERNET}, AppConstants.PERMISSION_REQ_CODE);
}
}else {
accessWebService();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == AppConstants.PERMISSION_REQ_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
accessWebService();
}else {
StringGenerator.showToast(ConfigurationActivity.this, "LOL");
}
}else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
accessWeb服务:
private void accessWebService(){
FetchDataTask task = new FetchDataTask();
task.execute(AppConstants.DATABASE_INFO_URL);
}
清单:
<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>
结果如下:
并且没有请求许可:
有什么建议么?