CoVer_App/app/src/main/java/com/example/cover_a01/MainActivity.java
/**
     * we need to make sure that both bluetooth and location permissions are granted for this app to work.
     */
we need to make sure that both bluetooth and location permissions are granted for this app to work.
we need to make sure that both bluetooth and location permissions are granted for this app to work .
private boolean checkPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                    == PackageManager.PERMISSION_GRANTED) {
                if (this.checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
                        != PackageManager.PERMISSION_GRANTED) {
                    try{
                        if (this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
                            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                            builder.setTitle("CoVer Tracing requires background location access");
                            builder.setMessage("Please grant background location access so this app can continuously detect other phones.");
                            builder.setPositiveButton(android.R.string.ok, null);
                            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                                @TargetApi(23)
                                @Override
                                public void onDismiss(DialogInterface dialog) {
                                    requestPermissions(new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
                                            PERMISSION_REQUEST_BACKGROUND_LOCATION);
                                }
                            });
                            builder.show();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                if (!this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                                    Manifest.permission.ACCESS_BACKGROUND_LOCATION},
                            PERMISSION_REQUEST_FINE_LOCATION);
                }
                else {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Missing Permission");
                    builder.setMessage("Without location access this App cannot function as intended. Please change Permissions via Settings menu");
                    builder.setPositiveButton(android.R.string.ok, null);
                    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                        }
                    });
                    builder.show();
                }
            }
        }
        return false;
    }
private boolean checkPermission ( ) { if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) { if ( this . checkSelfPermission ( Manifest . permission . ACCESS_FINE_LOCATION ) == PackageManager . PERMISSION_GRANTED ) { if ( this . checkSelfPermission ( Manifest . permission . ACCESS_BACKGROUND_LOCATION ) != PackageManager . PERMISSION_GRANTED ) { try { if ( this . shouldShowRequestPermissionRationale ( Manifest . permission . ACCESS_BACKGROUND_LOCATION ) ) { final AlertDialog . Builder builder = new AlertDialog . Builder ( this ) ; builder . setTitle ( "CoVer Tracing requires background location access" ) ; builder . setMessage ( "Please grant background location access so this app can continuously detect other phones." ) ; builder . setPositiveButton ( android . R . string . ok , null ) ; builder . setOnDismissListener ( new DialogInterface . OnDismissListener ( ) { @ TargetApi ( 23 ) @ Override public void onDismiss ( DialogInterface dialog ) { requestPermissions ( new String [ ] { Manifest . permission . ACCESS_BACKGROUND_LOCATION } , PERMISSION_REQUEST_BACKGROUND_LOCATION ) ; } } ) ; builder . show ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } else { if ( ! this . shouldShowRequestPermissionRationale ( Manifest . permission . ACCESS_FINE_LOCATION ) ) { requestPermissions ( new String [ ] { Manifest . permission . ACCESS_FINE_LOCATION , Manifest . permission . ACCESS_BACKGROUND_LOCATION } , PERMISSION_REQUEST_FINE_LOCATION ) ; } else { final AlertDialog . Builder builder = new AlertDialog . Builder ( this ) ; builder . setTitle ( "Missing Permission" ) ; builder . setMessage ( "Without location access this App cannot function as intended. Please change Permissions via Settings menu" ) ; builder . setPositiveButton ( android . R . string . ok , null ) ; builder . setOnDismissListener ( new DialogInterface . OnDismissListener ( ) { @ Override public void onDismiss ( DialogInterface dialog ) { } } ) ; builder . show ( ) ; } } } return false ; }
we need to make sure that both bluetooth and location permissions are granted for this app to work.
we need to make sure that both bluetooth and location permissions are granted for this app to work .