我面临一个奇怪的问题。我遵循this教程,以便在运行时为我构建的应用程序请求权限。问题是,即使我检查设备是否使用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);
}
}
accessWebService:
private void accessWebService(){
FetchDataTask task = new FetchDataTask();
task.execute(AppConstants.DATABASE_INFO_URL);
}
The Manifest:
<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>
结果如下:
并没有要求许可:
任何建议?