Java Code Examples for android.content.pm.PackageManager.PERMISSION_DENIED

The following are Jave code examples for showing how to use PERMISSION_DENIED of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Mvp-Retrofit-Rxjava-Rxbus   File: AppInfoUtils.java   View Source Code Vote up 7 votes
/**
 * 有做M上的权限兼容
 * @param context
 * @return
 */
public static String getPhoneIMEI(Context context) {
    String deviceID = "";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int permissionResult = context.checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);
        if (permissionResult == PackageManager.PERMISSION_DENIED) {
            permissionResult = context.checkCallingOrSelfPermission("android.permission.READ_PRIVILEGED_PHONE_STATE");
        }
        boolean isPermissionGranted = permissionResult == PackageManager.PERMISSION_GRANTED;
        if (!isPermissionGranted) {
            deviceID = getDeviceIDFromReflection(context);
        } else {
            deviceID = getDeviceIDFromSystem(context);
        }
    } else {
        deviceID = getDeviceIDFromSystem(context);
    }

    Log.i(TAG,"getPhoneIMEI : " + deviceID);
    return deviceID;
}
 
Example 2
Project: VirtualAPK   File: BookManagerService.java   View Source Code Vote up 6 votes
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
        throws RemoteException {
    int check = checkCallingOrSelfPermission("com.ryg.chapter_2.permission.ACCESS_BOOK_SERVICE");
    Log.d(TAG, "check=" + check);
    if (check == PackageManager.PERMISSION_DENIED) {
        //return false;
    }

    String packageName = null;
    String[] packages = getPackageManager().getPackagesForUid(
            getCallingUid());
    if (packages != null && packages.length > 0) {
        packageName = packages[0];
    }
    Log.d(TAG, "onTransact: " + packageName);
    if (!packageName.startsWith("com.ryg")) {
        //return false;
    }

    return super.onTransact(code, data, reply, flags);
}
 
Example 3
Project: siiMobilityAppKit   File: Screenshot.java   View Source Code Vote up 6 votes
public void onRequestPermissionResult(int requestCode, String[] permissions,
                                      int[] grantResults) throws JSONException
{
    for(int r:grantResults)
    {
        if(r == PackageManager.PERMISSION_DENIED)
        {
            mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
            return;
        }
    }
    switch(requestCode)
    {
        case SAVE_SCREENSHOT_SEC:
            saveScreenshot();
            break;
        case SAVE_SCREENSHOT_URI_SEC:
            getScreenshotAsURI();
            break;
    }
}
 
Example 4
Project: mobile-app-dev-book   File: AudioActivity.java   View Source Code Vote up 6 votes
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == AUDIO_PERMISSION_REQUEST && permissions[0]
            .equals(android.Manifest.permission.RECORD_AUDIO)) {
        if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                boolean showAgain =
                        shouldShowRequestPermissionRationale
                                (android.Manifest.permission.RECORD_AUDIO);
                if (showAgain) {

                }
            }
            finish(); // can't use audio
        }
    } else
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
 
Example 5
Project: siiMobilityAppKit   File: BLECentralPlugin.java   View Source Code Vote up 6 votes
public void onRequestPermissionResult(int requestCode, String[] permissions,
                                      int[] grantResults) /* throws JSONException */ {
    for(int result:grantResults) {
        if(result == PackageManager.PERMISSION_DENIED)
        {
            LOG.d(TAG, "User *rejected* Coarse Location Access");
            this.permissionCallback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
            return;
        }
    }

    switch(requestCode) {
        case REQUEST_ACCESS_COARSE_LOCATION:
            LOG.d(TAG, "User granted Coarse Location Access");
            findLowEnergyDevices(permissionCallback, serviceUUIDs, scanSeconds);
            this.permissionCallback = null;
            this.serviceUUIDs = null;
            this.scanSeconds = -1;
            break;
    }
}
 
Example 6
Project: Clipcon-AndroidClient   File: MainActivity.java   View Source Code Vote up 6 votes
public void writeExternalStoragePrmissionCheck() {
    /* 사용자의 OS 버전이 마시멜로우 이상인지 체크한다. */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        /* 사용자 단말기의 권한 중 "저장소 쓰기" 권한이 허용되어 있는지 체크한다.
         */
        int permissionResult = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);

        /* WRITE_EXTERNAL_STORAGE의 권한이 없을 때 */
        if (permissionResult == PackageManager.PERMISSION_DENIED) {
            /* 사용자가 WRITE_EXTERNAL_STORAGE의 권한을 한번이라도 거부한 적이 있는 지 조사한다.
             * 거부한 이력이 한번이라도 있다면, true를 리턴한다.
             */
            requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_STORAGE);
        }
    }
}
 
Example 7
Project: kognitivo   File: Validate.java   View Source Code Vote up 6 votes
public static void hasInternetPermissions(Context context, boolean shouldThrow) {
    Validate.notNull(context, "context");
    if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET) ==
            PackageManager.PERMISSION_DENIED) {
        if (shouldThrow) {
            throw new IllegalStateException(NO_INTERNET_PERMISSION_REASON);
        } else {
            Log.w(TAG, NO_INTERNET_PERMISSION_REASON);
        }
    }
}
 
Example 8
Project: MobileAppForPatient   File: AllDeviceListActivity.java   View Source Code Vote up 6 votes
/**
 * connect to the bluetooth
 *
 * @param deviceInfo
 */
private void connectToBluetooth(final DeviceInfoBean deviceInfo) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            switch (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION)) {
                case PackageManager.PERMISSION_DENIED:
                    performPermissionDeniedAction(deviceInfo);
                    break;
                case PackageManager.PERMISSION_GRANTED:
                    startDeviceConnection(deviceInfo, healthCareReceiver);
                    break;
                default:
                    break;
            }
        } else {
            startDeviceConnection(deviceInfo, healthCareReceiver);
        }

    } catch (RuntimeException e) {
        showToastMessage(e.getMessage(), mContext);
        Log.e(AppUtility.TAG, Log.getStackTraceString(e));
    }

}
 
Example 9
Project: siiMobilityAppKit   File: Calendar.java   View Source Code Vote up 6 votes
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
  for (int r : grantResults) {
    if (r == PackageManager.PERMISSION_DENIED) {
      Log.d(LOG_TAG, "Permission Denied!");
      this.callback.error("Please allow access to the Calendar and try again.");
      return;
    }
  }

  // now call the originally requested actions
  if (requestCode == PERMISSION_REQCODE_CREATE_CALENDAR) {
    createCalendar(requestArgs);
  } else if (requestCode == PERMISSION_REQCODE_DELETE_CALENDAR) {
    deleteCalendar(requestArgs);
  } else if (requestCode == PERMISSION_REQCODE_CREATE_EVENT) {
    createEvent(requestArgs);
  } else if (requestCode == PERMISSION_REQCODE_DELETE_EVENT) {
    deleteEvent(requestArgs);
  } else if (requestCode == PERMISSION_REQCODE_FIND_EVENTS) {
    findEvents(requestArgs);
  } else if (requestCode == PERMISSION_REQCODE_LIST_CALENDARS) {
    listCalendars();
  } else if (requestCode == PERMISSION_REQCODE_LIST_EVENTS_IN_RANGE) {
    listEventsInRange(requestArgs);
  }
}
 
Example 10
Project: localcloud_fe   File: CameraLauncher.java   View Source Code Vote up 6 votes
public void onRequestPermissionResult(int requestCode, String[] permissions,
                                      int[] grantResults) throws JSONException {
    for (int r : grantResults) {
        if (r == PackageManager.PERMISSION_DENIED) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
            return;
        }
    }
    switch (requestCode) {
        case TAKE_PIC_SEC:
            takePicture(this.destType, this.encodingType);
            break;
        case SAVE_TO_ALBUM_SEC:
            this.getImage(this.srcType, this.destType, this.encodingType);
            break;
    }
}
 
Example 11
Project: emerald   File: BackupPreference.java   View Source Code Vote up 5 votes
@Override
public void onClick() {
	// request runtime permissions (Marshmallow+)
       if (Build.VERSION.SDK_INT >= 23) {
       	if ((getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
       		|| (getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)) {
       		((Options)getContext()).requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
       		return;
       	} else {
       		super.onClick();
       	}
       } else {
       	super.onClick();
       }
}
 
Example 12
Project: mobile-app-dev-book   File: TripMapFragment.java   View Source Code Vote up 5 votes
@Override
public void onMapReady(GoogleMap googleMap) {
    gMap = googleMap;
    gMap.setOnInfoWindowClickListener(this);
    if (ContextCompat.checkSelfPermission(getActivity(), permArr[0]) ==
            PackageManager.PERMISSION_DENIED)
        requestPermissions(permArr, LOCATION_PERM_REQUEST);
    else
        gMap.setMyLocationEnabled(true);
    mapReady = true;
    if (dataReady) refreshMarkers();
}
 
Example 13
Project: FastAndroid   File: BaseFragment.java   View Source Code Vote up 5 votes
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    for (int i = 0; i < grantResults.length; i++) {
        if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
            permissionResponse(requestCode, false);
            showPermissionWarn();
            return;
        }
    }
    permissionResponse(requestCode, true);
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
 
Example 14
Project: alerta-fraude   File: AudioHandler.java   View Source Code Vote up 5 votes
public void onRequestPermissionResult(int requestCode, String[] permissions,
                                      int[] grantResults) throws JSONException
{
    for(int r:grantResults)
    {
        if(r == PackageManager.PERMISSION_DENIED)
        {
            this.messageChannel.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
            return;
        }
    }
    promptForRecord();
}
 
Example 15
Project: AR   File: RequestPermissionsActivity.java   View Source Code Vote up 5 votes
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_PERMISSION) {
        // for each permission check if the user granted/denied them
        // you may want to group the rationale in a single dialog,
        // this is just an example
        int len = permissions.length;
        for (int i = 0; i < len; i++) {
            String permission = permissions[i];
            if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                // user rejected the permission
                boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(RequestPermissionsActivity.this, permission );
                if (! showRationale) {
                    // user also CHECKED "never ask again"
                    // you can either enable some fall back,
                    // disable features of your app
                    // or open another dialog explaining
                    // again the permission and directing to
                    // the app setting

                } else if (Manifest.permission.WRITE_CONTACTS.equals(permission)) {
                    // todo define strings
                    showRationale(permission, R.string.permission_denied_contacts);
                    // user did NOT check "never ask again"
                    // this is a good place to explain the user
                    // why you need the permission and ask if he wants
                    // to accept it (the rationale)
                }
                //else if ( /* possibly check more permissions...*/ ) {}
            }
        }
    }
}
 
Example 16
Project: TPlayer   File: VPackageManagerService.java   View Source Code Vote up 5 votes
@Override
public int checkPermission(String permName, String pkgName, int userId) {
    if ("android.permission.INTERACT_ACROSS_USERS".equals(permName)
            || "android.permission.INTERACT_ACROSS_USERS_FULL".equals(permName)) {
        return PackageManager.PERMISSION_DENIED;
    }
    return VirtualCore.get().getPackageManager().checkPermission(permName, VirtualCore.get().getHostPkg());
}
 
Example 17
Project: phonk   File: PermissionsActivity.java   View Source Code Vote up 5 votes
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    boolean isPermissionWriteExternalGranted = false;

    switch (requestCode) {
        case REQUEST_CODE_SOME_FEATURES_PERMISSIONS: {
            for (int i = 0; i < permissions.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    MLog.d("Permissions", "Permission Granted: " + permissions[i]);
                } else if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                    MLog.d("Permissions", "Permission Denied: " + permissions[i]);
                }

                if (permissions[i].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    isPermissionWriteExternalGranted = true;
                    MLog.d(TAG, "granted!");
                }
                // if is already granted we remove it from the list
                // requiredPermissions.remove(i);
            }

            // if ok go next step otherwise repeat step
            if (isPermissionWriteExternalGranted) {
                // goToStep(STEP_ASK_PERMISSIONS_OK);
            } else {
                // goToStep(STEP_ASK_PERMISSIONS_ERROR);
            }
        }
        break;
        default: {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}
 
Example 18
Project: Recognize-it   File: PermissionUtils.java   View Source Code Vote up 4 votes
public static boolean isGrantedResult(int... permissionResult) {
    for (int result : permissionResult) {
        if (result == PackageManager.PERMISSION_DENIED) return false;
    }
    return true;
}
 
Example 19
Project: FirebasePost   File: PermissionsHelper.java   View Source Code Vote up 2 votes
/**
 * use for check @param permission is PERMISSION_DENIED or not
 *
 * @param context
 * @param permission
 * @return
 */
private static boolean isPermissionDenied(Context context, String permission) {
    return PermissionChecker.checkSelfPermission(context, permission) ==
            PackageManager.PERMISSION_DENIED;
}
 
Example 20
Project: homunculus   File: Permissions.java   View Source Code Vote up 2 votes
/**
 * Checks the denied flag
 *
 * @return true if denied
 */
public boolean isDenied() {
    return result == PackageManager.PERMISSION_DENIED;
}