List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED
int PERMISSION_GRANTED
To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.
Click Source Link
From source file:MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case SEND_SMS_PERMISSION_REQUEST_CODE: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mButtonSend.setEnabled(true); }// w ww.j av a2 s . c om return; } } }
From source file:br.com.anteros.android.persistence.backup.ExportDatabaseTask.java
public static String executarBackup(String databaseName, String databasePath, SharedPreferences preferences, Context context) {//from ww w. j ava2s. c o m if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { throw new BackupException( "No foi possvel executar a tarefa de backup pois voc no possu permisso para isto. Verifique se solicitou permisso no manifesto ou requisitou a permisso caso esteja usando Android(Marshmallow) 6 ou acima."); } File dbFile = new File(databasePath); File exportDir = new File(Environment.getExternalStorageDirectory(), "backup"); if (!exportDir.exists()) { exportDir.mkdirs(); } if (countBackupFiles(exportDir, dbFile.getName()) >= maxBackupFiles) { deleteOldBackup(exportDir, dbFile.getName()); } lastBackup = new File(exportDir, generateBackupName(dbFile)); try { lastBackup.createNewFile(); AndroidFileUtils.copyFile(dbFile, lastBackup); SharedPreferences.Editor editor = preferences.edit(); editor.putLong(BackupService.DATE_TIME_LAST_BACKUP, new Date().getTime()); editor.commit(); } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } SQLiteDatabase db = null; try { db = context.openOrCreateDatabase(databaseName, SQLiteDatabase.OPEN_READWRITE, null); db.execSQL("vacuum;"); db.execSQL("reindex;"); } catch (Exception e) { e.printStackTrace(); } finally { try { db.close(); } catch (Exception e2) { } } return "OK"; }
From source file:casariego.jorge.createpdf.Pdf1Activity.java
/** * Checks if the app has permission to write to device storage * * If the app does not has permission then the user will be prompted to grant permissions * * @param activity/* w w w . j a v a 2 s .c om*/ */ public static void verifyStoragePermissions(Activity activity) { // Check if we have write permission if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); } } else { createPDF(); } }
From source file:am.project.x.utils.ContextUtils.java
/** * ???// w w w . j a va2 s . c o m * * @param context Context * @return ??? */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean hasWriteExternalStoragePermission(Context context) { return Build.VERSION.SDK_INT < 23 || ActivityCompat.checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; }
From source file:butter.droid.tv.activities.TVLaunchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent recommendationIntent = new Intent(this, RecommendationService.class); startService(recommendationIntent);// w w w .ja va 2s .c o m if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST); return; } proceedCreate(); }
From source file:cn.jarlen.mediaplayer.sample.application.AppActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//www. j a v a2 s.c o m if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { // TODO: show explanation } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); } } }
From source file:cn.nekocode.camerafilter.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);// ww w . ja va 2s .c o m setTitle("Original"); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { Toast.makeText(this, "Camera access is required.", Toast.LENGTH_SHORT).show(); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, REQUEST_CAMERA_PERMISSION); } } else { setupCameraPreviewView(); } }
From source file:cn.motalks.mtdc.utils.EasyPermissionsEx.java
/** * Check if the calling context has a set of permissions. * * @param context the calling context.//from w ww.j av a 2 s . co m * @param perms one ore more permissions, such as {@code android.Manifest.permission.CAMERA}. * @return true if all permissions are already granted, false if at least one permission * is not yet granted. */ public static boolean hasPermissions(Context context, String... perms) { // Always return true for SDK < M, let the system deal with the permissions if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { Log.w(TAG, "hasPermissions: API version < M, returning true by default"); return true; } for (String perm : perms) { boolean hasPerm = (ActivityCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_GRANTED); if (!hasPerm) { return false; } } return true; }
From source file:cc.metapro.openct.utils.CrashHandler.java
@Override public void uncaughtException(Thread thread, final Throwable ex) { if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { try {/*from ww w . j ava2s. c om*/ dumpExceptionToSDCard(ex); if (mDefaultHandler != null) { mDefaultHandler.uncaughtException(thread, ex); } new Thread(new Runnable() { @Override public void run() { Looper.prepare(); Toast.makeText(mContext, R.string.crash_pop, Toast.LENGTH_LONG).show(); Looper.loop(); } }).start(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.aftabsikander.permissionassist.PermissionAssistant.java
/** * Check if the calling context has a set of permissions. * * @param context the calling context.//from ww w . ja v a 2s. c o m * @param perms one ore more permissions, such as {@link Manifest.permission#CAMERA}. * @return true if all permissions are already granted, false if at least one permission is not * yet granted. * @see Manifest.permission */ public static boolean hasPermissions(@NonNull Context context, @NonNull String... perms) { if (PermissionUtil.isMDevice()) { for (String perm : perms) { boolean hasPerm = (ContextCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_GRANTED); if (!hasPerm) { return false; } } } else { return true; } return true; }