サンプルソースコードをhttps://github.com/googlemaps/android-samples/tree/master/tutorials/CurrentPlaceDetailsOnMapからダウンロードしました。許可の無限ループをリクエスト
これは、2つの関数の無限ループによって引き起こさ初めての実行時にクラッシュした:
private void updateLocationUI() {
if (mMap == null) {
return;
}
/*
* Request location permission, so that we can get the location of the
* device. The result of the permission request is handled by a callback,
* onRequestPermissionsResult.
*/
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mLocationPermissionGranted = true;
} else {
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
}
if (mLocationPermissionGranted) {
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
} else {
mMap.setMyLocationEnabled(false);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mLastKnownLocation = null;
}
}
と
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
@NonNull int[] grantResults) {
mLocationPermissionGranted = false;
switch (requestCode) {
case PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mLocationPermissionGranted = true;
}
}
}
updateLocationUI();
}
し、エミュレータ上でそれを実行します。APIのlvl25を、Androd 7.1.1
ログ:
03-22 23:34:18.249 24660-24660/com.example.mypc.mapdemo W/Activity: Can reqeust only one set of permissions at a time
03-22 23:34:19.759 24660-24660/com.example.mypc.mapdemo W/Activity: Can reqeust only one set of permissions at a time
03-22 23:34:20.501 24660-24660/com.example.mypc.mapdemo W/Activity: Can reqeust only one set of permissions at a time
03-22 23:34:20.894 24660-24660/com.example.mypc.mapdemo W/Activity: Can reqeust only one set of permissions at a time
クラッシュログ:
E/AndroidRuntime: at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:372)
at com.example.mypc.mapdemo.MainActivity.updateLocationUI(MainActivity.java:330)
at com.example.mypc.mapdemo.MainActivity.onRequestPermissionsResult(MainActivity.java:207)
at android.app.Activity.requestPermissions(Activity.java:4116)
at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompatApi23.java:49)
at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:37
```2)
質問:私はそれをどのように修正することができますか?
あなたの答えの説明はありますか? –
'requestpermission'の' override'メソッドのコードを置き換えて –
私にこれを知らせるかどうかを教えてください。 –