androidx.core.app.ActivityCompat Java Examples

The following examples show how to use androidx.core.app.ActivityCompat. 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: LoginActivity.java    From dtube-mobile-unofficial with Apache License 2.0 6 votes vote down vote up
public void qrButtonClicked(View v){
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.CAMERA},
                CAMERA_REQUEST_PERMISSION);
    }else {
        if (passwordEditText.isEnabled()) {

            Intent qrIntent = new Intent(LoginActivity.this, SimpleScannerActivity.class);
            startActivityForResult(qrIntent, RESULT_QR_CODE);

        }
    }
}
 
Example #2
Source File: Settings.java    From Passbook with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
void getPermission2Do(String text, int type, int operation, int option){
    String permission = operation == ActionDialog.ACTION_IMPORT ?
            Manifest.permission.READ_EXTERNAL_STORAGE :
            Manifest.permission.WRITE_EXTERNAL_STORAGE;

    if (ActivityCompat.checkSelfPermission(this, permission)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{permission},
                PERMISSION_REQUEST);
        mActionType = type;
        mText = text;
        mOperation = operation;
        mOption = option;
    }
    else {
        new ImportExportTask(this, text, Application.getInstance().getPassword(),
                type, operation, option).execute();
    }
}
 
Example #3
Source File: GlobalPrivilegeClaimingActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void refreshUI() {
    TextView enabledTextView = findViewById(R.id.enabled_textview);
    TextView notEnabledTextView = findViewById(R.id.not_enabled_textview);
    Button claimButton = findViewById(R.id.claim_button);
    TextView instructions = findViewById(R.id.instructions);

    if (GlobalPrivilegesManager.getEnabledPrivileges().size() > 0) {
        notEnabledTextView.setVisibility(View.GONE);
        claimButton.setVisibility(View.GONE);
        instructions.setVisibility(View.GONE);
        enabledTextView.setVisibility(View.VISIBLE);
        enabledTextView.setText(getEnabledText());
    } else {
        enabledTextView.setVisibility(View.GONE);
        claimButton.setVisibility(View.VISIBLE);
        instructions.setVisibility(View.VISIBLE);
        notEnabledTextView.setVisibility(View.VISIBLE);
    }
    ActivityCompat.invalidateOptionsMenu(this);
}
 
Example #4
Source File: BLEProvisionLanding.java    From esp-idf-provisioning-android with Apache License 2.0 6 votes vote down vote up
private void startScan() {

        if (!hasPermissions() || isScanning) {
            return;
        }

        isScanning = true;
        deviceList.clear();
        bluetoothDevices.clear();

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            provisionManager.searchBleEspDevices(deviceNamePrefix, bleScanListener);
            updateProgressAndScanBtn();
        } else {
            Log.e(TAG, "Not able to start scan as Location permission is not granted.");
            Toast.makeText(BLEProvisionLanding.this, "Please give location permission to start BLE scan", Toast.LENGTH_LONG).show();
        }
    }
 
Example #5
Source File: MainActivity.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
private void requestPermissionsIfNotGranted(String[] perms, int resultCode) {
    ArrayList<String> permissionsToAskFor = new ArrayList<>();
    if (perms != null) { // This is created (or not) by the child activity
        for (String permissionToHave : perms) {
            if (!checkPermission(permissionToHave)) {
                permissionsToAskFor.add(permissionToHave);
            }
        }
    }

    if (permissionsToAskFor.size() > 0) {
        for (String permission : permissionsToAskFor) {
            Log.i("[Permission] Requesting " + permission + " permission");
        }
        String[] permissions = new String[permissionsToAskFor.size()];
        permissions = permissionsToAskFor.toArray(permissions);

        KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        boolean locked = km.inKeyguardRestrictedInputMode();
        if (!locked) {
            // This is to workaround an infinite loop of pause/start in Activity issue
            // if incoming call ends while screen if off and locked
            ActivityCompat.requestPermissions(this, permissions, resultCode);
        }
    }
}
 
Example #6
Source File: PictureSelectActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 处理请求权限的响应
 *
 * @param requestCode  请求码
 * @param permissions  权限数组
 * @param grantResults 请求权限结果数组
 */
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    boolean isPermissions = true;
    for (int i = 0; i < permissions.length; i++) {
        if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
            isPermissions = false;
            if (!ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[i])) { //用户选择了"不再询问"
                if (isToast) {
                    Toast.makeText(this, "请手动打开该应用需要的权限", Toast.LENGTH_SHORT).show();
                    isToast = false;
                }
            }
        }
    }
    isToast = true;
    if (isPermissions) {
        Log.d("onRequestPermission", "onRequestPermissionsResult: " + "允许所有权限");
        selectPicture();
    } else {
        Log.d("onRequestPermission", "onRequestPermissionsResult: " + "有权限不允许");
        finish();
    }
}
 
Example #7
Source File: NovelItemListFragment.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onItemClick(View view, final int position) {
    //Toast.makeText(getActivity(),"item click detected", Toast.LENGTH_SHORT).show();
    if(position < 0 || position >= listNovelItemAid.size()) {
        // ArrayIndexOutOfBoundsException
        Toast.makeText(getActivity(), "ArrayIndexOutOfBoundsException: " + position + " in size " + listNovelItemAid.size(), Toast.LENGTH_SHORT).show();
        return;
    }

    // go to detail activity
    Intent intent = new Intent(getActivity(), NovelInfoActivity.class);
    intent.putExtra("aid", listNovelItemAid.get(position));
    intent.putExtra("from", "list");
    intent.putExtra("title", ((TextView) view.findViewById(R.id.novel_title)).getText());

    if(Build.VERSION.SDK_INT < 21) {
        startActivity(intent);
    }
    else {
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                Pair.create(view.findViewById(R.id.novel_cover), "novel_cover"),
                Pair.create(view.findViewById(R.id.novel_title), "novel_title"));
        ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    }
}
 
Example #8
Source File: GroupChatFragment.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void requestStoragePermissions() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Snackbar.make(mRootLayout, getString(R.string.request_external_storage),
                Snackbar.LENGTH_LONG)
                .setAction(getString(R.string.accept_permission), new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                })
                .show();
    } else {
        // Permission has not been granted yet. Request it directly.
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_EXTERNAL_STORAGE);
    }
}
 
Example #9
Source File: ComicBrowserFragment.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
/*************************
 * Favorite Modification
 ************************/

@Override
protected boolean modifyFavorites(MenuItem item) {
    if (!prefHelper.isOnline(getActivity())) {
        Toast.makeText(getActivity(), R.string.no_connection, Toast.LENGTH_SHORT).show();
        return true;
    }
    if (databaseManager.isFavorite(lastComicNumber)) {
        //new DeleteComicImageTask(lastComicNumber).execute(true);
        removeFavorite(lastComicNumber, true);
        item.setIcon(R.drawable.ic_favorite_off_24dp);
    } else {
        if (!(ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
            ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
            return true;
        }
        //new SaveComicImageTask(lastComicNumber).execute(true);
        addFavorite(lastComicNumber, true);
        item.setIcon(R.drawable.ic_favorite_on_24dp);
    }
    return true;
}
 
Example #10
Source File: CustomSlideNotify.java    From haven with GNU General Public License v3.0 6 votes vote down vote up
private void askForPermission(String permission, Integer requestCode) {
    if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {

            //This is called if user has denied the permission before
            //In this case I am just asking the permission again
            ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);

        } else {

            ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
        }
    } else {
    }
}
 
Example #11
Source File: PermissionUtils.java    From android-samples with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    final int requestCode = arguments.getInt(ARGUMENT_PERMISSION_REQUEST_CODE);
    finishActivity = arguments.getBoolean(ARGUMENT_FINISH_ACTIVITY);

    return new AlertDialog.Builder(getActivity())
            .setMessage(R.string.permission_rationale_location)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // After click on Ok, request the permission.
                    ActivityCompat.requestPermissions(getActivity(),
                            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                            requestCode);
                    // Do not finish the Activity while requesting permission.
                    finishActivity = false;
                }
            })
            .setNegativeButton(android.R.string.cancel, null)
            .create();
}
 
Example #12
Source File: QrActivity.java    From yubikit-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qr_scan);
    surfaceView = findViewById(R.id.surfaceView);
    if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
        initQrReader();
    } else {
        setResult(GOOGLE_PLAY_SERVICES_UNAVAILABLE);
        finish();
    }

    if (qrReader != null) {
        if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CAMERA);
        }
    }
}
 
Example #13
Source File: AppUtils.java    From loco-answers with GNU General Public License v3.0 6 votes vote down vote up
private static String getUserIdentity(Context context) {
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) ==
            PackageManager.PERMISSION_GRANTED) {
        AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
        @SuppressLint("MissingPermission") Account[] list = manager.getAccounts();
        String emailId = null;
        for (Account account : list) {
            if (account.type.equalsIgnoreCase("com.google")) {
                emailId = account.name;
                break;
            }
        }
        if (emailId != null) {
            return emailId;
        }
    }
    return "";
}
 
Example #14
Source File: ConfigActivity.java    From Field-Book with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dt = new DataHelper(this);

    ep = getSharedPreferences("Settings", 0);

    invalidateOptionsMenu();
    loadScreen();

    // request permissions
    ActivityCompat.requestPermissions(this, Constants.permissions, Constants.PERM_REQ);
    createDirs();

    if (ep.getInt("UpdateVersion", -1) < Utils.getVersion(this)) {
        ep.edit().putInt("UpdateVersion", Utils.getVersion(this)).apply();
        showChangelog(true, false);
    }

    checkIntent();
}
 
Example #15
Source File: MainActivity.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public void requestPermission() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE
            }, MY_PERMISSIONS_WRITE_STORAGE);

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{
                            Manifest.permission.WRITE_EXTERNAL_STORAGE
                    },
                    MY_PERMISSIONS_WRITE_STORAGE);

        }
    } else onPermissionGranted();
}
 
Example #16
Source File: VideoBrowserFragment.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
public void itemClicked(View view, MediaInfo item, int position) {
    if (view instanceof ImageButton) {
        Utils.showQueuePopup(getActivity(), view, item);
    } else {
        String transitionName = getString(R.string.transition_image);
        VideoListAdapter.ViewHolder viewHolder =
                (VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
        Pair<View, String> imagePair = Pair
                .create((View) viewHolder.getImageView(), transitionName);
        ActivityOptionsCompat options = ActivityOptionsCompat
                .makeSceneTransitionAnimation(getActivity(), imagePair);

        Intent intent = new Intent(getActivity(), LocalPlayerActivity.class);
        intent.putExtra("media", item);
        intent.putExtra("shouldStart", false);
        ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
    }
}
 
Example #17
Source File: PlacesActivity.java    From nearby-android with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the {@link Manifest.permission#ACCESS_FINE_LOCATION}
 * permission.
 */

private void requestLocationPermission() {
  if (ActivityCompat.checkSelfPermission(this,
          Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || mUserDeniedPermission) {
    // Permission has been granted (or denied and ignored), set up the toolbar and fragments.
    setUpToolbar();
    setUpFragments();
  } else {
    ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION},
            PERMISSION_REQUEST_LOCATION);
  }
}
 
Example #18
Source File: AndroidLocationProvider.java    From BLE-Indoor-Positioning with Apache License 2.0 5 votes vote down vote up
public static void requestLocationPermission(@NonNull Activity activity) {
    Log.d(TAG, "Requesting location permission");
    ActivityCompat.requestPermissions(activity, new String[]{
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION
    }, REQUEST_CODE_LOCATION_PERMISSIONS);
}
 
Example #19
Source File: LogcatActivity.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
private void showSendLogDialog() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    SEND_LOG_ID_REQUEST);
            return;
        }

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        @SuppressLint("InflateParams") View includeDeviceInfoView = inflater.inflate(R.layout.dialog_send_log, null, false);
        final CheckBox includeDeviceInfoCheckBox = includeDeviceInfoView.findViewById(android.R.id.checkbox);

        // allow user to choose whether or not to include device info in report, use preferences for persistence
        includeDeviceInfoCheckBox.setChecked(PreferenceHelper.getIncludeDeviceInfoPreference(this));
        includeDeviceInfoCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> PreferenceHelper.setIncludeDeviceInfoPreference(LogcatActivity.this, isChecked));

        final CheckBox includeDmesgCheckBox = includeDeviceInfoView.findViewById(R.id.checkbox_dmesg);

        // allow user to choose whether or not to include device info in report, use preferences for persistence
        includeDmesgCheckBox.setChecked(PreferenceHelper.getIncludeDmesgPreference(this));
        includeDmesgCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> PreferenceHelper.setIncludeDmesgPreference(LogcatActivity.this, isChecked));

        new MaterialDialog.Builder(LogcatActivity.this)
                .title(R.string.share_log)
                .customView(includeDeviceInfoView, false)
                .negativeText(android.R.string.cancel)
                .positiveText(android.R.string.ok)
                .onPositive((materialDialog, dialogAction) -> {
                    sendLogToTargetApp(false, includeDeviceInfoCheckBox.isChecked(), includeDmesgCheckBox.isChecked());
                    materialDialog.dismiss();
                }).show();
    }
 
Example #20
Source File: ActivityTransitionLauncher.java    From candybar with Apache License 2.0 5 votes vote down vote up
public void launch(Intent intent) {

        intent.putExtras(createBundle());
        if (Build.VERSION.SDK_INT >= 16) {
            ActivityCompat.startActivity(activity, intent, createOptions());
            return;
        }
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }
 
Example #21
Source File: JumpUtils.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到视频播放
 *
 * @param activity
 * @param view
 */
public static void goToVideoPickPlayer(Activity activity, View view) {
    Intent intent = new Intent(activity, PlayPickActivity.class);
    intent.putExtra(PlayActivity.TRANSITION, true);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Pair pair = new Pair<>(view, PlayActivity.IMG_TRANSITION);
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
                activity, pair);
        ActivityCompat.startActivity(activity, intent, activityOptions.toBundle());
    } else {
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
    }
}
 
Example #22
Source File: MainActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (hasPermissions(this, RUNTIME_PERMISSIONS)) {
        setupMapFragmentView();
    } else {
        ActivityCompat
                .requestPermissions(this, RUNTIME_PERMISSIONS, REQUEST_CODE_ASK_PERMISSIONS);
    }
}
 
Example #23
Source File: DownloadView.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkPermissions() {
    if (ActivityCompat.checkSelfPermission(this.getContext(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        fragment.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_PERMISSION);
        return true;
    }
    return false;
}
 
Example #24
Source File: PspdfkitPlugin.java    From pspdfkit-flutter with Apache License 2.0 5 votes vote down vote up
private void requestPermission(String permission) {
    Activity activity = registrar.activity();
    permission = getManifestPermission(permission);
    if (permission == null) {
        return;
    }
    Log.i(LOG_TAG, "Requesting permission " + permission);
    String[] perm = {permission};
    ActivityCompat.requestPermissions(activity, perm, 0);
}
 
Example #25
Source File: AddDeviceActivity.java    From esp-idf-provisioning-android with Apache License 2.0 5 votes vote down vote up
private void alertForWiFi() {

        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
        builder.setCancelable(false);
        builder.setMessage(R.string.error_wifi_off);

        // Set up the buttons
        builder.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
                espDevice = null;
                hideLoading();
                if (codeScanner != null) {
                    codeScanner.releaseResources();
                    codeScanner.startPreview();
                    if (ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                            && ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
                        provisionManager.scanQRCode(codeScanner, qrCodeScanListener);
                    } else {
                        Log.e(TAG, "Permissions are not granted");
                    }
                }
            }
        });

        builder.show();
    }
 
Example #26
Source File: LogcatActivity.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
private void showSaveLogZipDialog() {

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    SEND_LOG_ID_REQUEST);
            return;
        }

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        @SuppressLint("InflateParams") View includeDeviceInfoView = inflater.inflate(R.layout.dialog_send_log, null, false);
        final CheckBox includeDeviceInfoCheckBox = includeDeviceInfoView.findViewById(android.R.id.checkbox);

        // allow user to choose whether or not to include device info in report, use preferences for persistence
        includeDeviceInfoCheckBox.setChecked(PreferenceHelper.getIncludeDeviceInfoPreference(this));
        includeDeviceInfoCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> PreferenceHelper.setIncludeDeviceInfoPreference(LogcatActivity.this, isChecked));

        final CheckBox includeDmesgCheckBox = includeDeviceInfoView.findViewById(R.id.checkbox_dmesg);

        // allow user to choose whether or not to include device info in report, use preferences for persistence
        includeDmesgCheckBox.setChecked(PreferenceHelper.getIncludeDmesgPreference(this));
        includeDmesgCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> PreferenceHelper.setIncludeDmesgPreference(LogcatActivity.this, isChecked));

        new MaterialDialog.Builder(LogcatActivity.this)
                .title(R.string.save_log_zip)
                .customView(includeDeviceInfoView, false)
                .negativeText(android.R.string.cancel)
                .positiveText(android.R.string.ok)
                .onPositive((materialDialog, dialogAction) -> {
                    saveLogToTargetApp(includeDeviceInfoCheckBox.isChecked(), includeDmesgCheckBox.isChecked());
                    materialDialog.dismiss();
                }).show();
    }
 
Example #27
Source File: PermissionsFragment.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public void ensurePermission(final @NonNull String permission) {
    Builder dialogBuilder = new AlertDialog.Builder(getActivity())
            .setCancelable(false);

    if (ActivityCompat.checkSelfPermission(getActivity(), permission) != PERMISSION_GRANTED ||
            ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {
        dialogBuilder.setTitle(R.string.location_permission_dialog_title)
                .setMessage(R.string.location_permission_dialog_text)
                .setPositiveButton(R.string.got_it, (dialog, which) -> {
                    dialog.dismiss();
                    requestPermission(permission);
                });
    } else {
        // user has explicitly denied this permission to setup.
        // show a simple dialog and bail out.
        dialogBuilder.setTitle(R.string.location_permission_denied_dialog_title)
                .setMessage(R.string.location_permission_denied_dialog_text)
                .setPositiveButton(R.string.settings, (dialog, which) -> {
                    dialog.dismiss();
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    String pkgName = getActivity().getApplicationInfo().packageName;
                    intent.setData(Uri.parse("package:" + pkgName));
                    startActivity(intent);
                })
                .setNegativeButton(R.string.exit_setup, (dialog, which) -> {
                    Client client = (Client) getActivity();
                    client.onUserDeniedPermission(permission);
                });
    }

    dialogBuilder.show();
}
 
Example #28
Source File: FFmpegCommandActivity.java    From FFmpegCommand with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ffmpeg_command);
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                100);
    }
    init();
}
 
Example #29
Source File: AndroidPermission.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressLint("BatteryLife")
private static void askForPermission(Activity activity, String[] permission, Integer requestCode) {
    boolean test = false;
    boolean testBattery = false;
    for (String s : permission) {
        test = test || (ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED);
        if (s.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) {
            PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
            String packageName = activity.getPackageName();
            testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName);
        }
    }
    if (test) {
        ActivityCompat.requestPermissions(activity, permission, requestCode);
    }
    if (testBattery) {
        try {
            Intent i = new Intent();
            i.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            i.setData(Uri.parse("package:" + activity.getPackageName()));
            activity.startActivityForResult(i, CASE_BATTERY);
        } catch (ActivityNotFoundException e) {
            permission_battery_optimization_failed = true;
            OKDialog.show(activity, MainApp.gs(R.string.permission), MainApp.gs(R.string.alert_dialog_permission_battery_optimization_failed), activity::recreate);
        }
    }
}
 
Example #30
Source File: MainActivity.java    From location-samples with Apache License 2.0 5 votes vote down vote up
private void requestPermissions() {
    boolean shouldProvideRationale =
            ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_FINE_LOCATION);

    // Provide an additional rationale to the user. This would happen if the user denied the
    // request previously, but didn't check the "Don't ask again" checkbox.
    if (shouldProvideRationale) {
        Log.i(TAG, "Displaying permission rationale to provide additional context.");
        showSnackbar(R.string.permission_rationale,
                android.R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        // Request permission
                        ActivityCompat.requestPermissions(MainActivity.this,
                                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                REQUEST_PERMISSIONS_REQUEST_CODE);
                    }
                });
    } else {
        Log.i(TAG, "Requesting permission");
        // Request permission. It's possible this can be auto answered if device policy
        // sets the permission in a given state or the user denied the permission
        // previously and checked "Never ask again".
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                REQUEST_PERMISSIONS_REQUEST_CODE);
    }
}