List of usage examples for android.provider Settings ACTION_MANAGE_WRITE_SETTINGS
String ACTION_MANAGE_WRITE_SETTINGS
To view the source code for android.provider Settings ACTION_MANAGE_WRITE_SETTINGS.
Click Source Link
From source file:com.github.yuqilin.qmediaplayerapp.util.Permissions.java
private static Dialog createSettingsDialogCompat(final Activity activity, int mode) { int titleId = 0, textId = 0; String action = Settings.ACTION_MANAGE_WRITE_SETTINGS; switch (mode) { case PERMISSION_SYSTEM_RINGTONE: titleId = R.string.allow_settings_access_ringtone_title; textId = R.string.allow_settings_access_ringtone_description; break;/*from w w w. ja va 2 s. c o m*/ case PERMISSION_SYSTEM_BRIGHTNESS: titleId = R.string.allow_settings_access_brightness_title; textId = R.string.allow_settings_access_brightness_description; break; case PERMISSION_SYSTEM_DRAW_OVRLAYS: titleId = R.string.allow_draw_overlays_title; textId = R.string.allow_sdraw_overlays_description; action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION; break; } final String finalAction = action; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId)) .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); Intent i = new Intent(finalAction); i.setData(Uri.parse("package:" + activity.getPackageName())); try { activity.startActivity(i); } catch (Exception ex) { } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_settings_access", true); Util.commitPreferences(editor); } }); return dialogBuilder.show(); }
From source file:com.tml.sharethem.sender.SHAREthemActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sender); //init UI/*from ww w .ja v a2 s . c o m*/ m_sender_wifi_info = (TextView) findViewById(R.id.p2p_sender_wifi_hint); m_noReceiversText = (TextView) findViewById(R.id.p2p_no_receivers_text); m_showShareList = (TextView) findViewById(R.id.p2p_sender_items_label); m_showShareList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showSharedFilesDialog(); } }); m_receivers_list_layout = (RelativeLayout) findViewById(R.id.p2p_receivers_list_layout); m_receiversList = (RecyclerView) findViewById(R.id.p2p_receivers_list); m_apControlSwitch = (SwitchCompat) findViewById(R.id.p2p_sender_ap_switch); m_toolbar = (Toolbar) findViewById(R.id.toolbar); m_toolbar.setTitle(getString(R.string.send_title)); setSupportActionBar(m_toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); hotspotControl = HotspotControl.getInstance(getApplicationContext()); m_receiversList.setLayoutManager(new LinearLayoutManager(getApplicationContext())); m_receiversList .addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.list_divider))); //if file paths are found, save'em into preferences. OR find them in prefs if (null != getIntent() && getIntent().hasExtra(SHAREthemService.EXTRA_FILE_PATHS)) m_sharedFilePaths = getIntent().getStringArrayExtra(SHAREthemService.EXTRA_FILE_PATHS); SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); if (null == m_sharedFilePaths) m_sharedFilePaths = Utils.toStringArray(prefs.getString(PREFERENCES_KEY_SHARED_FILE_PATHS, null)); else prefs.edit().putString(PREFERENCES_KEY_SHARED_FILE_PATHS, new JSONArray(Arrays.asList(m_sharedFilePaths)).toString()).apply(); m_receiversListAdapter = new ReceiversListingAdapter(new ArrayList<HotspotControl.WifiScanResult>(), m_sharedFilePaths); m_receiversList.setAdapter(m_receiversListAdapter); m_sender_ap_switch_listener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (!isOreoOrAbove()) { //If target version is MM and beyond, you need to check System Write permissions to proceed. if (Build.VERSION.SDK_INT >= 23 && // if targetSdkVersion >= 23 // ShareActivity has to check for System Write permissions to proceed Utils.getTargetSDKVersion(getApplicationContext()) >= 23 && !Settings.System.canWrite(SHAREthemActivity.this)) { changeApControlCheckedStatus(false); showMessageDialogWithListner( getString(R.string.p2p_sender_system_settings_permission_prompt), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent, REQUEST_WRITE_SETTINGS); } }, false, true); return; } else if (!getSharedPreferences(getPackageName(), Context.MODE_PRIVATE) .getBoolean(PREFERENCES_KEY_DATA_WARNING_SKIP, false) && Utils.isMobileDataEnabled(getApplicationContext())) { changeApControlCheckedStatus(false); showDataWarningDialog(); return; } } else if (!checkLocationPermission()) { changeApControlCheckedStatus(false); return; } enableAp(); } else { changeApControlCheckedStatus(true); showMessageDialogWithListner(getString(R.string.p2p_sender_close_warning), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d(TAG, "sending intent to service to stop p2p.."); resetSenderUi(true); } }, true, false); } } }; m_apControlSwitch.setOnCheckedChangeListener(m_sender_ap_switch_listener); m_p2pServerUpdatesListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isFinishing() || null == intent) return; int intentType = intent.getIntExtra(SHAREthemService.ShareIntents.TYPE, 0); if (intentType == SHAREthemService.ShareIntents.Types.FILE_TRANSFER_STATUS) { String fileName = intent .getStringExtra(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATE_FILE_NAME); updateReceiverListItem(intent.getStringExtra(SHAREthemService.ShareIntents.SHARE_CLIENT_IP), intent.getIntExtra(SHAREthemService.ShareIntents.SHARE_TRANSFER_PROGRESS, -1), intent.getStringExtra(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATE_TEXT), fileName); } else if (intentType == SHAREthemService.ShareIntents.Types.AP_DISABLED_ACKNOWLEDGEMENT) { shouldAutoConnect = false; resetSenderUi(false); } } }; registerReceiver(m_p2pServerUpdatesListener, new IntentFilter(SHAREthemService.ShareIntents.SHARE_SERVER_UPDATES_INTENT_ACTION)); }
From source file:org.videolan.vlc.util.Permissions.java
private static Dialog createSettingsDialogCompat(final Activity activity, int mode) { int titleId = 0, textId = 0; String action = Settings.ACTION_MANAGE_WRITE_SETTINGS; switch (mode) { case PERMISSION_SYSTEM_RINGTONE: titleId = R.string.allow_settings_access_ringtone_title; textId = R.string.allow_settings_access_ringtone_description; break;/*from ww w .j av a2 s .c o m*/ case PERMISSION_SYSTEM_BRIGHTNESS: titleId = R.string.allow_settings_access_brightness_title; textId = R.string.allow_settings_access_brightness_description; break; case PERMISSION_SYSTEM_DRAW_OVRLAYS: titleId = R.string.allow_draw_overlays_title; textId = R.string.allow_sdraw_overlays_description; action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION; break; } final String finalAction = action; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId)) .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); Intent i = new Intent(finalAction); i.setData(Uri.parse("package:" + activity.getPackageName())); try { activity.startActivity(i); } catch (Exception ex) { } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_settings_access", true); editor.apply(); } }); return dialogBuilder.show(); }
From source file:projekt.substratum.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); startService(new Intent(this, ThemeService.class)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . ja v a2s . c o m getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(false); AccountHeader header = new AccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.material_drawer_header_background).withProfileImagesVisible(false) .withSelectionListEnabledForSingleProfile(false).addProfiles(new ProfileDrawerItem() .withName(getString(R.string.drawer_name)).withEmail(BuildConfig.VERSION_NAME)) .withCurrentProfileHiddenInList(true).build(); final LibsSupportFragment fragment = new LibsBuilder().supportFragment(); if (References.checkOMS()) { drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header) .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true) .addDrawerItems( new PrimaryDrawerItem().withName(R.string.nav_home) .withIcon(R.drawable.nav_theme_packs), new PrimaryDrawerItem().withName(R.string.nav_overlays) .withIcon(R.drawable.nav_overlays), new PrimaryDrawerItem().withName(R.string.nav_bootanim) .withIcon(R.drawable.nav_bootanim), new PrimaryDrawerItem().withName(R.string.nav_fonts).withIcon(R.drawable.nav_fonts), new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds), new SectionDrawerItem().withName(R.string.nav_section_header_utilities), new PrimaryDrawerItem().withName(R.string.nav_overlay_manager) .withIcon(R.drawable.nav_overlay_manager), new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage), new PrimaryDrawerItem().withName(R.string.nav_priorities) .withIcon(R.drawable.nav_drawer_priorities), new PrimaryDrawerItem().withName(R.string.nav_backup_restore) .withIcon(R.drawable.nav_drawer_profiles), new SectionDrawerItem().withName(R.string.nav_section_header_more), new SecondaryDrawerItem().withName(R.string.nav_troubleshooting) .withIcon(R.drawable.nav_troubleshooting), new SecondaryDrawerItem().withName(R.string.nav_team) .withIcon(R.drawable.nav_drawer_team), new SecondaryDrawerItem().withName(getString(R.string.nav_opensource)) .withIcon(R.drawable.nav_drawer_licenses), new SecondaryDrawerItem().withName(R.string.nav_settings) .withIcon(R.drawable.nav_drawer_settings)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem != null) { switch (position) { case 1: if (drawerSelected != position) { switchFragment(((References.checkOMS()) ? getString(R.string.app_name) : getString(R.string.legacy_app_name)), "HomeFragment"); drawerSelected = 1; } break; case 2: if (drawerSelected != position) { switchFragment(getString(R.string.nav_overlays), "OverlaysFragment"); drawerSelected = 2; } break; case 3: if (drawerSelected != position) { switchFragment(getString(R.string.nav_bootanim), "BootAnimationsFragment"); drawerSelected = 3; } break; case 4: if (drawerSelected != position) { switchFragment(getString(R.string.nav_fonts), "FontsFragment"); drawerSelected = 4; } break; case 5: if (drawerSelected != position) { switchFragment(getString(R.string.nav_sounds), "SoundsFragment"); drawerSelected = 5; } break; case 7: switchFragment(getString(R.string.nav_overlay_manager), "AdvancedManagerFragment"); drawerSelected = 7; break; case 8: switchFragment(getString(R.string.nav_manage), "ManageFragment"); drawerSelected = 8; break; case 9: switchFragment(getString(R.string.nav_priorities), "PriorityLoaderFragment"); drawerSelected = 9; break; case 10: switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment"); drawerSelected = 10; break; case 12: if (drawerSelected != position) { switchFragment(getString(R.string.nav_troubleshooting), "TroubleshootingFragment"); drawerSelected = 12; } break; case 13: if (drawerSelected != position) { switchFragment(getString(R.string.nav_team), "TeamFragment"); drawerSelected = 13; } break; case 14: switchFragmentToLicenses(getString(R.string.nav_opensource), fragment); drawerSelected = 14; break; case 15: if (drawerSelected != position) { switchFragment(getString(R.string.nav_settings), "SettingsFragment"); drawerSelected = 15; } break; } } return false; } }).withSelectedItem(1).withSelectedItemByPosition(1).build(); } else { drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header) .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true) .addDrawerItems( new PrimaryDrawerItem().withName(R.string.nav_home) .withIcon(R.drawable.nav_theme_packs), new PrimaryDrawerItem().withName(R.string.nav_overlays) .withIcon(R.drawable.nav_overlays), new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds), new SectionDrawerItem().withName(R.string.nav_section_header_utilities), new PrimaryDrawerItem().withName(R.string.nav_overlay_manager) .withIcon(R.drawable.nav_overlay_manager), new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage), new PrimaryDrawerItem().withName(R.string.nav_backup_restore) .withIcon(R.drawable.nav_drawer_profiles), new SectionDrawerItem().withName(R.string.nav_section_header_more), new SecondaryDrawerItem().withName(R.string.nav_troubleshooting) .withIcon(R.drawable.nav_troubleshooting), new SecondaryDrawerItem().withName(R.string.nav_team) .withIcon(R.drawable.nav_drawer_team), new SecondaryDrawerItem().withName(getString(R.string.nav_opensource)) .withIcon(R.drawable.nav_drawer_licenses), new SecondaryDrawerItem().withName(R.string.nav_settings) .withIcon(R.drawable.nav_drawer_settings)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem != null) { switch (position) { case 1: if (drawerSelected != position) { switchFragment(((References.checkOMS()) ? getString(R.string.app_name) : getString(R.string.legacy_app_name)), "HomeFragment"); drawerSelected = 1; } break; case 2: if (drawerSelected != position) { switchFragment(getString(R.string.nav_overlays), "OverlaysFragment"); drawerSelected = 2; } break; case 3: if (drawerSelected != position) { switchFragment(getString(R.string.nav_sounds), "SoundsFragment"); drawerSelected = 3; } break; case 5: switchFragment(getString(R.string.nav_overlay_manager), "AdvancedManagerFragment"); drawerSelected = 5; break; case 6: switchFragment(getString(R.string.nav_manage), "ManageFragment"); drawerSelected = 6; break; case 7: switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment"); drawerSelected = 7; break; case 9: if (drawerSelected != position) { switchFragment(getString(R.string.nav_troubleshooting), "TroubleshootingFragment"); drawerSelected = 10; } break; case 10: if (drawerSelected != position) { switchFragment(getString(R.string.nav_team), "TeamFragment"); drawerSelected = 10; } break; case 11: switchFragmentToLicenses(getString(R.string.nav_opensource), fragment); drawerSelected = 11; break; case 12: if (drawerSelected != position) { switchFragment(getString(R.string.nav_settings), "SettingsFragment"); drawerSelected = 12; } break; } } return false; } }).withSelectedItem(1).withSelectedItemByPosition(1).build(); } if (!Root.requestRootAccess()) { final ProgressDialog mProgressDialog = new ProgressDialog(this, R.style.SubstratumBuilder_ActivityTheme); mProgressDialog.setIndeterminate(false); mProgressDialog.setCancelable(false); mProgressDialog.show(); mProgressDialog.setContentView(R.layout.root_rejected_loader); final float radius = 5; final View decorView = getWindow().getDecorView(); final View rootView = decorView.findViewById(android.R.id.content); final Drawable windowBackground = decorView.getBackground(); BlurView blurView = (BlurView) mProgressDialog.findViewById(R.id.blurView); blurView.setupWith(rootView).windowBackground(windowBackground) .blurAlgorithm(new RenderScriptBlur(this, true)).blurRadius(radius); final TextView textView = (TextView) mProgressDialog.findViewById(R.id.timer); CountDownTimer Count = new CountDownTimer(5000, 1000) { public void onTick(long millisUntilFinished) { if ((millisUntilFinished / 1000) > 1) { textView.setText(String.format(getString(R.string.root_rejected_timer_plural), (millisUntilFinished / 1000) + "")); } else { textView.setText(String.format(getString(R.string.root_rejected_timer_singular), (millisUntilFinished / 1000) + "")); } } public void onFinish() { mProgressDialog.dismiss(); finish(); } }; Count.start(); } permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.System.canWrite(getApplicationContext())) { Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + MainActivity.this.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { Log.d("SubstratumLogger", "Substratum was granted " + "'android.permission.WRITE_SETTINGS' " + "permissions for system runtime code execution."); } } if (permissionCheck == PackageManager.PERMISSION_GRANTED) { // permission already granted, allow the program to continue running File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } File cacheDirectory = new File(getCacheDir(), "/SubstratumBuilder/"); if (!cacheDirectory.exists()) { cacheDirectory.mkdirs(); } if (permissionCheck2 == PackageManager.PERMISSION_GRANTED) { // permission already granted, allow the program to continue running // Set the first option to start at app boot drawer.setSelectionAtPosition(1); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_PHONE_STATE }, PERMISSIONS_REQUEST_READ_PHONE_STATE); } } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } // Now, let's grab root on the helper Intent rootIntent = new Intent(Intent.ACTION_MAIN); rootIntent.setAction("masquerade.substratum.INITIALIZE"); try { startActivity(rootIntent); } catch (RuntimeException re) { // Exception: At this point, Masquerade is not installed at all. } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (References.checkOMS()) { if (!prefs.getBoolean("substratum_oms", true)) { Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/"); Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/"); File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } } } else { if (prefs.getBoolean("substratum_oms", true)) { Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/"); Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/"); File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } } } printFCMtoken(); }
From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java
private boolean checkSettingsAccess() { // TODO: by default, applications are not granted access, but the settings switch shows access is allowed - need to // TODO: toggle this switch to actually grant access. Need to improve this interaction generally if (!canWriteSettings()) { AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this); builder.setTitle(R.string.title_settings_access); builder.setMessage(R.string.hint_enable_settings_access); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override/*from w w w. jav a 2s . c o m*/ public void onDismiss(DialogInterface dialog) { // note: dismiss rather than cancel so we always take this action (pos or neg result) if (checkSettingsAccess()) { if (mConnectionMode == ConnectionMode.CONNECTION_INITIATED_HOTSPOT) { createHotspot(); return; } } mConnectionMode = ConnectionMode.SCANNING; setupDefaultUI(); } }); builder.setPositiveButton(R.string.hint_edit_settings_access, new DialogInterface.OnClickListener() { @TargetApi(Build.VERSION_CODES.M) @Override public void onClick(DialogInterface dialog, int which) { try { Intent settingsIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); settingsIntent.setData(Uri.parse("package:" + PluginIntent.HOST_PACKAGE)); startActivity(settingsIntent); } catch (ActivityNotFoundException e) { Toast.makeText(ConnectionSetupActivity.this, R.string.error_editing_settings, Toast.LENGTH_LONG).show(); // TODO: reset ui? } dialog.dismiss(); } }); builder.setNeutralButton(R.string.button_done, null); builder.show(); return false; } return true; }