The APP often uses geographic location authorization. The following describes the encapsulation of gps and suspension window on Android
Only part of the code and the creation of interaction classes are shown here Portal
Design sketch
There's a problem here. Because Android manufacturers are different, when users refuse to authorize geographical location, they can't accurately transfer to the corresponding permission management of the app, so they just jump to the application information page
Application details page
@ReactMethod //Check whether the floating window is open public void checkFloatWindowOpen() { final Activity activity = getCurrentActivity() ; if(Build.VERSION.SDK_INT >= 23){ if (!Settings.canDrawOverlays(mReactContent)) { AlertDialog.Builder builder=new AlertDialog.Builder(activity); builder.setTitle("APP Suspension window permission is not opened"); builder.setMessage("Please allow APP Open suspended window permission"); builder.setPositiveButton("To set", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { //The first parameter, dialog, is the dialog object to which the confirm button belongs, and the second parameter, which is the marked value of the button //System location is not open Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName())); activity.startActivityForResult(intent, 1234); } }); builder.show(); } else { //startService(floatWinIntent); // activity.startService(floatWinIntent); } }; } @ReactMethod public void checkGpsOpen(){ final Activity activity = getCurrentActivity() ; LocationManager locationManager = (LocationManager) mReactContent.getSystemService(Context.LOCATION_SERVICE); // Through GPS satellite positioning, the positioning level can be accurate to the street (through 24 satellites positioning, positioning in outdoor and open places is accurate and fast) boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // Location (also known as AGPS) determined by WLAN or mobile network (3G/2G) to assist GPS positioning. It is mainly used for positioning indoors or in places with dense coverings (buildings or dense deep forest, etc.) // boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (gps ) { //Location service opened //Determine whether the application is authorized to allow positioning int checkResult = this.checkOp(this.getReactApplicationContext(),2,AppOpsManager.OPSTR_FINE_LOCATION); if (AppOpsManagerCompat.MODE_IGNORED == checkResult ) { AlertDialog.Builder builder=new AlertDialog.Builder(activity); builder.setTitle("Location permission is turned off"); builder.setMessage("Please set up-Application permissions (Open location permission"); builder.setPositiveButton("To set", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { //The first parameter, dialog, is the dialog object to which the confirm button belongs, and the second parameter, which is the marked value of the button //System location is not open // Intent localIntent = new Intent(Settings.ACTION_SETTINGS); Intent localIntent = new Intent(); localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= 9) { localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); localIntent.setData(Uri.fromParts("package", activity.getPackageName(), null)); } else if (Build.VERSION.SDK_INT <= 8) { localIntent.setAction(Intent.ACTION_VIEW); localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); localIntent.putExtra("com.android.settings.ApplicationPkgName", activity.getPackageName()); } activity.startActivity(localIntent); } }); builder.show(); } }else{ //Object to create the constructor for AlertDialog AlertDialog.Builder builder=new AlertDialog.Builder(activity); builder.setTitle("Location service is not enabled"); builder.setMessage("Please set up-position information (Open location service))"); builder.setPositiveButton("To set", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { //The first parameter, dialog, is the dialog object to which the confirm button belongs, and the second parameter, which is the marked value of the button //System location is not open Intent intent = new Intent(); intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS); activity.startActivityForResult(intent, 1315); } }); builder.show(); } } public int checkOp(Context context, int op, String opString) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { Object object = context.getSystemService(Context.APP_OPS_SERVICE); // Object object = context.getSystemService("appops"); Class c = object.getClass(); try { Class[] cArg = new Class[3]; cArg[0] = int.class; cArg[1] = int.class; cArg[2] = String.class; Method lMethod = c.getDeclaredMethod("checkOp", cArg); return (Integer) lMethod.invoke(object, op, Binder.getCallingUid(), context.getPackageName()); } catch (Exception e) { e.printStackTrace(); if (Build.VERSION.SDK_INT >= 23) { return AppOpsManagerCompat.noteOp(context, opString,context.getApplicationInfo().uid, context.getPackageName()); } } } return -1; }
As for the use of alert dialog, Android's pop-up box, don't forget to use show() to display it.