我使用GenyMotion虚拟机来测试我的Android应用程序,我下载了两个版本:6.0 a和7.1。该应用程序完美适用于7.1这意味着当我打开它时,它会请求权限,当我授予权限时,应用程序会下载所需的内容。 但是在6.0上只会弹出权限请求对话框,虽然我单击“确定”,但它会退出。可能是什么问题?
由于
if (!(is_connection())) {
Toast.makeText(this, "You need to connect to the Internet to get the latest version!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(WelcomeActitvity.this, MainActivity.class);
this.startActivity(intent);
} else {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Toast.makeText(this, "Android Marshmallow or above it", Toast.LENGTH_SHORT)
.show();
ActivityCompat.requestPermissions(WelcomeActitvity.this, new String[]{android.Manifest
.permission
.READ_EXTERNAL_STORAGE}, 1);
} else {
Toast.makeText(this, "Android Marshmallow or below it", Toast.LENGTH_SHORT)
.show();
textDownloader();
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[]
grantResults) {
switch (requestCode) {
case 1: {
// permission was granted
if (grantResults.length > 0 && grantResults[0] == PackageManager
.PERMISSION_GRANTED) {
textDownloader();
} else {
// permission denied
Toast.makeText(this, "Permission denied to read your External storage", Toast
.LENGTH_SHORT).show();
}
}
}
}
public void textDownloader() {
//downloads some stuff
}