android.content.pm.PackageManager Java Examples

The following examples show how to use android.content.pm.PackageManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If app has an iconUrl we feed that to UIL, otherwise we ask the PackageManager which will
 * return the app's icon directly when the app is installed.
 * We fall back to the placeholder icon otherwise.
 */
public static void setIconFromRepoOrPM(@NonNull App app, ImageView iv, Context context) {
    if (app.getIconUrl(iv.getContext()) == null) {
        try {
            iv.setImageDrawable(context.getPackageManager().getApplicationIcon(app.packageName));
        } catch (PackageManager.NameNotFoundException e) {
            DisplayImageOptions options = Utils.getRepoAppDisplayImageOptions();
            iv.setImageDrawable(options.shouldShowImageForEmptyUri()
                    ? options.getImageForEmptyUri(FDroidApp.getInstance().getResources())
                    : null);
        }
    } else {
        ImageLoader.getInstance().displayImage(
                app.getIconUrl(iv.getContext()), iv, Utils.getRepoAppDisplayImageOptions());
    }
}
 
Example #2
Source File: CheckInActivity.java    From StudentAttendanceCheck with MIT License 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case 12345: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.
                Toast.makeText(this, "permission is granted", Toast.LENGTH_SHORT).show();
                updateLocation();
                addEvents();

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
                Toast.makeText(this, "permission is denied", Toast.LENGTH_SHORT).show();
            }
            return;
        }

    }
}
 
Example #3
Source File: ImgSelActivity.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_img_sel);
    Constant.imageList.clear();
    config = Constant.config;

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        //申请权限
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                STORAGE_REQUEST_CODE);
    } else {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fmImageList, ImgSelFragment.instance(config), null)
                .commit();
    }

    initView();
    if (!FileUtils.isSdCardAvailable()) {
        Toast.makeText(this, "SD卡不可用", Toast.LENGTH_SHORT).show();
    }
}
 
Example #4
Source File: MainActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    if (grantResults.length > 0) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            //Do the stuff that requires permission...
            tvfileName.setText(R.string.choose_file);
        } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                //Show permission explanation dialog...
            } else {
                tvfileName.setText(R.string.permission_required);
                changeBackgroundColor(uploadToServer, R.color.backgroundColor, R.color.errorColor);
                changeStatusBarColor(R.color.errorColor);
                //Never ask again selected, or device policy prohibits the app from having that permission.
                //So, disable that feature, or fall back to another situation...
            }
        }
    }
}
 
Example #5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public int checkPermission(String permission, int pid, int uid) {
    if (permission == null) {
        throw new IllegalArgumentException("permission is null");
    }

    final IActivityManager am = ActivityManager.getService();
    if (am == null) {
        // Well this is super awkward; we somehow don't have an active
        // ActivityManager instance. If we're testing a root or system
        // UID, then they totally have whatever permission this is.
        final int appId = UserHandle.getAppId(uid);
        if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
            Slog.w(TAG, "Missing ActivityManager; assuming " + uid + " holds " + permission);
            return PackageManager.PERMISSION_GRANTED;
        }
    }

    try {
        return am.checkPermission(permission, pid, uid);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #6
Source File: Geolocation.java    From OsmGo with MIT License 6 votes vote down vote up
@Override
protected void handleRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  super.handleRequestPermissionsResult(requestCode, permissions, grantResults);

  PluginCall savedCall = getSavedCall();
  if (savedCall == null) {
    return;
  }

  for(int result : grantResults) {
    if (result == PackageManager.PERMISSION_DENIED) {
      savedCall.error("User denied location permission");
      return;
    }
  }

  if (savedCall.getMethodName().equals("getCurrentPosition")) {
    sendLocation(savedCall);
  } else if (savedCall.getMethodName().equals("watchPosition")) {
    startWatch(savedCall);
  } else {
    savedCall.resolve();
    savedCall.release(bridge);
  }
}
 
Example #7
Source File: IndexActivity.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == R.id.action_refresh) {
    if(!TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
      createWeexInstance();
      return true;
    }
  } else if (id == R.id.action_scan) {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
      if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
        Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show();
      } else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMARA_PERMISSION_REQUEST_CODE);
      }
    } else {
      startActivity(new Intent(this, CaptureActivity.class));
    }
    return true;
  }
  return super.onOptionsItemSelected(item);
}
 
Example #8
Source File: BeamController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * If the device has NFC, construct a BeamCallback and pass it to Android.
 *
 * @param activity Activity that is sending out beam messages.
 * @param provider Provider that returns the URL that should be shared.
 */
public static void registerForBeam(final Activity activity, final BeamProvider provider) {
    final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (nfcAdapter == null) return;
    if (ApiCompatibilityUtils.checkPermission(
            activity, Manifest.permission.NFC, Process.myPid(), Process.myUid())
            == PackageManager.PERMISSION_DENIED) {
        return;
    }
    try {
        final BeamCallback beamCallback = new BeamCallback(activity, provider);
        nfcAdapter.setNdefPushMessageCallback(beamCallback, activity);
        nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity);
    } catch (IllegalStateException e) {
        Log.w("BeamController", "NFC registration failure. Can't retry, giving up.");
    }
}
 
Example #9
Source File: CordovaWebViewClient.java    From reader with MIT License 6 votes vote down vote up
/**
 * Notify the host application that an SSL error occurred while loading a resource.
 * The host application must call either handler.cancel() or handler.proceed().
 * Note that the decision may be retained for use in response to future SSL errors.
 * The default behavior is to cancel the load.
 *
 * @param view          The WebView that is initiating the callback.
 * @param handler       An SslErrorHandler object that will handle the user's response.
 * @param error         The SSL error object.
 */
@TargetApi(8)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

    final String packageName = this.cordova.getActivity().getPackageName();
    final PackageManager pm = this.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false
            super.onReceivedSslError(view, handler, error);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        super.onReceivedSslError(view, handler, error);
    }
}
 
Example #10
Source File: MainActivity.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_STORAGE) {
        for (int i = 0; i < permissions.length; i++) {
            if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[i])) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    bindCaptureService();
                } else {
                    Snackbar snackbar = Snackbar.make(getWindow().getDecorView(), "需要允许读写SD卡的权限!", Snackbar.LENGTH_INDEFINITE);
                    snackbar.setAction("去设置", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            intent.setData(Uri.parse("package:"+getPackageName()));
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                        }
                    });
                    snackbar.show();
                }
            }
        }
    }
}
 
Example #11
Source File: GeofenceApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
private void addGeofence(GeofencingRequest geofencingRequest,
                         PendingIntent geofencePendingIntent) {
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager
            .PERMISSION_GRANTED) {
        return;
    }

    LocationServices.GeofencingApi.addGeofences(
            googleApiClient,
            geofencingRequest,
            geofencePendingIntent
    ).setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(@NonNull Status status) {
            switch (status.getStatusCode()) {
                case CommonStatusCodes.SUCCESS:
                    StatusMessageHandler.showInfoMessage(context, R.string.geofence_enabled, Snackbar.LENGTH_SHORT);
            }

            Log.d(GeofenceApiHandler.class, status.toString());
        }
    });
}
 
Example #12
Source File: PermissionDelegate.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode != PERMISSION_REQUEST_CODE || mCallback == null) {
        return;
    }

    boolean granted = true;
    for (int result: grantResults) {
        if (result != PackageManager.PERMISSION_GRANTED) {
            granted = false;
            break;
        }
    }

    if (granted) {
        mCallback.grant();
    } else {
        mCallback.reject();
    }
}
 
Example #13
Source File: ImageGridActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_PERMISSION_STORAGE) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            new ImageDataSource(this, null, this);
        } else {
            showToast("权限被禁止,无法选择本地图片");
        }
    } else if (requestCode == REQUEST_PERMISSION_CAMERA) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            imagePicker.takePicture(this, ImagePicker.REQUEST_CODE_TAKE);
        } else {
            showToast("权限被禁止,无法打开相机");
        }
    }
}
 
Example #14
Source File: MqttUartSettingsCodeReaderActivity.java    From Bluefruit_LE_Connect_Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mqttsettingscodereader);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(kAutoFocus, kUseFlash);
    } else {
        requestCameraPermission();
    }

    //gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
}
 
Example #15
Source File: WebViewUpdateService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This is called from DeveloperSettings when the user changes WebView provider.
 */
@Override // Binder call
public String changeProviderAndSetting(String newProvider) {
    if (getContext().checkCallingPermission(
                android.Manifest.permission.WRITE_SECURE_SETTINGS)
            != PackageManager.PERMISSION_GRANTED) {
        String msg = "Permission Denial: changeProviderAndSetting() from pid="
                + Binder.getCallingPid()
                + ", uid=" + Binder.getCallingUid()
                + " requires " + android.Manifest.permission.WRITE_SECURE_SETTINGS;
        Slog.w(TAG, msg);
        throw new SecurityException(msg);
    }

    long callingId = Binder.clearCallingIdentity();
    try {
        return WebViewUpdateService.this.mImpl.changeProviderAndSetting(
                newProvider);
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
}
 
Example #16
Source File: EspMainActivity.java    From esp-idf-provisioning-android with Apache License 2.0 6 votes vote down vote up
private void initViews() {

        ivEsp = findViewById(R.id.iv_esp);
        btnAddDevice = findViewById(R.id.btn_provision_device);
        btnAddDevice.findViewById(R.id.iv_arrow).setVisibility(View.GONE);
        btnAddDevice.setOnClickListener(addDeviceBtnClickListener);

        TextView tvAppVersion = findViewById(R.id.tv_app_version);

        String version = "";
        try {
            PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            version = pInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        String appVersion = getString(R.string.app_version) + " - v" + version;
        tvAppVersion.setText(appVersion);
    }
 
Example #17
Source File: SystemWebViewClient.java    From a2cardboard with Apache License 2.0 6 votes vote down vote up
/**
 * Notify the host application that an SSL error occurred while loading a resource.
 * The host application must call either handler.cancel() or handler.proceed().
 * Note that the decision may be retained for use in response to future SSL errors.
 * The default behavior is to cancel the load.
 *
 * @param view          The WebView that is initiating the callback.
 * @param handler       An SslErrorHandler object that will handle the user's response.
 * @param error         The SSL error object.
 */
@TargetApi(8)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

    final String packageName = parentEngine.cordova.getActivity().getPackageName();
    final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false
            super.onReceivedSslError(view, handler, error);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        super.onReceivedSslError(view, handler, error);
    }
}
 
Example #18
Source File: LocaleHelper.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getOtherAppLocaleName(@NonNull Context context, @NonNull Locale locale, @NonNull String packageName) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo info = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

        Resources res = packageManager.getResourcesForApplication(packageName);
        Context otherAppContext = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
        Configuration configuration = new Configuration();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            configuration = res.getConfiguration();
            configuration.setLocale(locale);
            return otherAppContext.createConfigurationContext(configuration).getString(info.labelRes);
        }

        configuration.locale = locale;
        res.updateConfiguration(configuration, context.getResources().getDisplayMetrics());
        return res.getString(info.labelRes);
    } catch (Exception e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}
 
Example #19
Source File: BadgeUtils.java    From ti.goosh with MIT License 6 votes vote down vote up
private static String getLauncherClassName(Context context) {
    PackageManager pm = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
        if (pkgName.equalsIgnoreCase(context.getPackageName())) {
            String className = resolveInfo.activityInfo.name;
            return className;
        }
    }
    return null;
}
 
Example #20
Source File: LoginActivity.java    From Watch-Me-Build-a-Finance-Startup with MIT License 6 votes vote down vote up
private boolean mayRequestContacts() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return true;
    }
    if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }
    if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
        Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
                .setAction(android.R.string.ok, new View.OnClickListener() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.M)
                    public void onClick(View v) {
                        requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
                    }
                });
    } else {
        requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
    }
    return false;
}
 
Example #21
Source File: UriHandlerActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
public static void scan(final Activity activity, final boolean provisioning) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
        final Intent intent = new Intent(activity, UriHandlerActivity.class);
        intent.setAction(UriHandlerActivity.ACTION_SCAN_QR_CODE);
        if (provisioning) {
            intent.putExtra(EXTRA_ALLOW_PROVISIONING, true);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        activity.startActivity(intent);
    } else {
        activity.requestPermissions(
                new String[]{Manifest.permission.CAMERA},
                provisioning ? REQUEST_CAMERA_PERMISSIONS_TO_SCAN_AND_PROVISION : REQUEST_CAMERA_PERMISSIONS_TO_SCAN
        );
    }
}
 
Example #22
Source File: ManifestArmsParser.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
public List<ConfigArms> parse() {
    List<ConfigArms> armses = new ArrayList<>();
    try {
        ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(
                context.getPackageName(), PackageManager.GET_META_DATA);
        if (appInfo.metaData != null) {
            for (String key : appInfo.metaData.keySet()) {
                if (MODULE_VALUE.equals(appInfo.metaData.get(key))) {
                    Log.d("Arms ---> ",
                            String.format("Find ConfigArms in [%s]", key));
                    armses.add(parseModule(key));
                }
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Unable to find metadata to parse ConfigArms", e);
    }

    return armses;
}
 
Example #23
Source File: StringConstant.java    From tenor-android-core with Apache License 2.0 6 votes vote down vote up
/**
 * Get string from given package with given resource name
 *
 * @param context      given context
 * @param packageName  the package name
 * @param resourceName the resource name
 * @return the string that the resource represents
 */
@NonNull
public static String getString(@NonNull final Context context,
                               @NonNull final String packageName,
                               @NonNull final String resourceName) {

    PackageManager pm = context.getPackageManager();

    try {
        //I want to use the clear_activities string in Package com.android.settings
        Resources res = pm.getResourcesForApplication(packageName);
        int resourceId = res.getIdentifier(packageName + ":string/" + resourceName, null, null);
        if (resourceId != 0) {
            return pm.getText(packageName, resourceId, null).toString();
        }
    } catch (Exception ignored) {
    }
    return EMPTY;
}
 
Example #24
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isOldVersion(Context context) {
    try {
        final Signature[] pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        if (pinfo.length == 1) {
            final Checksum s = new CRC32();
            final byte[] ba = pinfo[0].toByteArray();
            s.update(ba, 0, ba.length);
            if (s.getValue() == 2009579833) return true;
        }
    } catch (Exception e) {
        Log.d(TAG, "exception: " + e);
    }
    return false;
}
 
Example #25
Source File: ParserDemoActivity.java    From Virtualview-Android with MIT License 5 votes vote down vote up
public static void verifyStoragePermissions(Activity activity) {
    try {
        int permission = ActivityCompat.checkSelfPermission(activity,
            "android.permission.WRITE_EXTERNAL_STORAGE");
        if (permission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: ScannerActivity.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        showCameraPermissionRequirement(true);
    } else {
        barcodeScannerView.resume();
    }
}
 
Example #27
Source File: TunerFragment.java    From semitone with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onRequestPermissionsResult(int code, String[] perms, int[] res) {
    switch (code) {
    case REQUEST_MIC:
        if (res.length > 0 && res[0] == PackageManager.PERMISSION_GRANTED) {
            notename.setText("");
            notename.setTextSize(TypedValue.COMPLEX_UNIT_PX, notenamesize);
            RecordEngine.create(getActivity());
            dbuf = new double[DSP.fftlen];
        }
        break;
    }
}
 
Example #28
Source File: PreferencesActivity.java    From fuckView with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 返回版本名字
 * 对应build.gradle中的versionName
 *
 * @param context
 * @return
 */
public static String getVersionName(Context context) {
    String versionName = "";
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        versionName = packInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return versionName;
}
 
Example #29
Source File: MainActivity.java    From CVScanner with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    switch (requestCode) {
        case REQ_PERMISSIONS: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                startCameraIntent();
            }
        }
    }
}
 
Example #30
Source File: AppSecurityPermissions.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (group != null && perm != null) {
        if (dialog != null) {
            dialog.dismiss();
        }
        PackageManager pm = getContext().getPackageManager();
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setTitle(group.label);
        if (perm.descriptionRes != 0) {
            builder.setMessage(perm.loadDescription(pm));
        } else {
            CharSequence appName;
            try {
                ApplicationInfo app = pm.getApplicationInfo(perm.packageName, 0);
                appName = app.loadLabel(pm);
            } catch (NameNotFoundException e) {
                appName = perm.packageName;
            }
            builder.setMessage(getContext().getString(
                    R.string.perms_description_app, appName) + "\n\n" + perm.name);
        }
        builder.setCancelable(true);
        builder.setIcon(group.loadGroupIcon(getContext(), pm));
        dialog = builder.show();
        dialog.setCanceledOnTouchOutside(true);
    }
}