我在获得许可后获得了空白屏幕。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
int PERMISSION_ALL = 1;
String[] PERMISSIONS = {Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CAMERA};
if(!hasPermissions(this, PERMISSIONS)){
Log.d("permission","permission");
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
}
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
Log.d("requestCode",String.valueOf(requestCode));
switch (requestCode) {
case 1: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
//Do your work.
// finish();
//startActivity(getIntent());
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivityForResult(intent, 0);
} else {
Toast.makeText(this, "Until you grant the permission, we cannot proceed further", Toast.LENGTH_SHORT).show();
}
return;
}
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
我得到了要求相机和位置许可的对话框。在允许我得到一个空白屏幕并且手机挂起。
我得到"调试器不再活跃"没有别的。我正在获取允许权限对话框,但我没有获得权限标记,也没有调用我的OnRequestPermissionsResult()。
有人可以帮助我吗?
答案 0 :(得分:0)
我相信它是因为你并没有真正运行任何UI代码。例如,我在onRequestPermissionsResult()方法中授予权限后,我会更改您拥有的内容:
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivityForResult(intent, 0);
要渲染的任何UI。