List of usage examples for android.provider Settings ACTION_USAGE_ACCESS_SETTINGS
String ACTION_USAGE_ACCESS_SETTINGS
To view the source code for android.provider Settings ACTION_USAGE_ACCESS_SETTINGS.
Click Source Link
From source file:Main.java
public static void oepnSetting(Context context) { Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.getApplicationContext().startActivity(intent); }
From source file:Main.java
public static void openModule(Context context) { context.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); }
From source file:com.bms.mqp.behaviormodelsystem.AppUsageEventsFragment.java
/** * Returns the {@link #mRecyclerView} including the time span specified by the * intervalType argument.// w w w .jav a2s.c o m * * * @return A list of {@link UsageStats}. */ public UsageEvents getUsageStatistics() { // Get the app statistics since one year ago from the current time. Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -1); long now = System.currentTimeMillis(); UsageEvents queryUsageStats = mUsageStatsManager.queryEvents(mLastTime, now); if (!queryUsageStats.hasNextEvent()) { Log.i(TAG, "The user may not allow the access to apps usage. "); Toast.makeText(getActivity(), getString(R.string.explanation_access_to_appusage_is_not_enabled), Toast.LENGTH_LONG).show(); mOpenUsageSettingButton.setVisibility(View.VISIBLE); mOpenUsageSettingButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); } }); } return queryUsageStats; }
From source file:com.bms.mqp.behaviormodelsystem.AppUsageStatisticsFragment.java
/** * Returns the {@link #mRecyclerView} including the time span specified by the * intervalType argument.//from w ww. java2s . com * * @param intervalType The time interval by which the stats are aggregated. * Corresponding to the value of {@link UsageStatsManager}. * E.g. {@link UsageStatsManager#INTERVAL_DAILY}, {@link * UsageStatsManager#INTERVAL_WEEKLY}, * * @return A list of {@link android.app.usage.UsageStats}. */ public List<UsageStats> getUsageStatistics(int intervalType) { // Get the app statistics since one year ago from the current time. Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -1); List<UsageStats> queryUsageStats = mUsageStatsManager.queryUsageStats(intervalType, cal.getTimeInMillis(), System.currentTimeMillis()); if (queryUsageStats.size() == 0) { Log.i(TAG, "The user may not allow the access to apps usage. "); Toast.makeText(getActivity(), getString(R.string.explanation_access_to_appusage_is_not_enabled), Toast.LENGTH_LONG).show(); mOpenUsageSettingButton.setVisibility(View.VISIBLE); mOpenUsageSettingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); } }); } return queryUsageStats; }
From source file:com.phonegap.plugins.nativesettings.NativeSettings.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; Uri packageUri = Uri.parse("package:" + this.cordova.getActivity().getPackageName()); String result = ""; //Information on settings can be found here: //http://developer.android.com/reference/android/provider/Settings.html action = args.getString(0);/*from w ww . ja va 2 s .co m*/ Intent intent = null; if (action.equals("accessibility")) { intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); } else if (action.equals("account")) { intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); } else if (action.equals("airplane_mode")) { intent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS); } else if (action.equals("apn")) { intent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS); } else if (action.equals("application_details")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageUri); } else if (action.equals("application_development")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); } else if (action.equals("application")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS); } //else if (action.equals("battery_saver")) { // intent = new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS); //} else if (action.equals("bluetooth")) { intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS); } else if (action.equals("captioning")) { intent = new Intent(android.provider.Settings.ACTION_CAPTIONING_SETTINGS); } else if (action.equals("cast")) { intent = new Intent(android.provider.Settings.ACTION_CAST_SETTINGS); } else if (action.equals("data_roaming")) { intent = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS); } else if (action.equals("date")) { intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS); } else if (action.equals("about")) { intent = new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS); } else if (action.equals("display")) { intent = new Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS); } else if (action.equals("dream")) { intent = new Intent(android.provider.Settings.ACTION_DREAM_SETTINGS); } else if (action.equals("home")) { intent = new Intent(android.provider.Settings.ACTION_HOME_SETTINGS); } else if (action.equals("keyboard")) { intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS); } else if (action.equals("keyboard_subtype")) { intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); } else if (action.equals("storage")) { intent = new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS); } else if (action.equals("locale")) { intent = new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS); } else if (action.equals("location")) { intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); } else if (action.equals("manage_all_applications")) { intent = new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS); } else if (action.equals("manage_applications")) { intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); } else if (action.equals("memory_card")) { intent = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS); } else if (action.equals("network")) { intent = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS); } else if (action.equals("nfcsharing")) { intent = new Intent(android.provider.Settings.ACTION_NFCSHARING_SETTINGS); } else if (action.equals("nfc_payment")) { intent = new Intent(android.provider.Settings.ACTION_NFC_PAYMENT_SETTINGS); } else if (action.equals("nfc_settings")) { intent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS); } //else if (action.equals("notification_listner")) { // intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); //} else if (action.equals("print")) { intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS); } else if (action.equals("privacy")) { intent = new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS); } else if (action.equals("quick_launch")) { intent = new Intent(android.provider.Settings.ACTION_QUICK_LAUNCH_SETTINGS); } else if (action.equals("search")) { intent = new Intent(android.provider.Settings.ACTION_SEARCH_SETTINGS); } else if (action.equals("security")) { intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS); } else if (action.equals("settings")) { intent = new Intent(android.provider.Settings.ACTION_SETTINGS); } else if (action.equals("show_regulatory_info")) { intent = new Intent(android.provider.Settings.ACTION_SHOW_REGULATORY_INFO); } else if (action.equals("sound")) { intent = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS); } else if (action.equals("store")) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + this.cordova.getActivity().getPackageName())); } else if (action.equals("sync")) { intent = new Intent(android.provider.Settings.ACTION_SYNC_SETTINGS); } else if (action.equals("usage")) { intent = new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS); } else if (action.equals("user_dictionary")) { intent = new Intent(android.provider.Settings.ACTION_USER_DICTIONARY_SETTINGS); } else if (action.equals("voice_input")) { intent = new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS); } else if (action.equals("wifi_ip")) { intent = new Intent(android.provider.Settings.ACTION_WIFI_IP_SETTINGS); } else if (action.equals("wifi")) { intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); } else if (action.equals("wireless")) { intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); } else { status = PluginResult.Status.INVALID_ACTION; callbackContext.sendPluginResult(new PluginResult(status, result)); return false; } if (args.length() > 1 && args.getBoolean(1)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } this.cordova.getActivity().startActivity(intent); callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:fabiogentile.powertutor.ui.UMLogger.java
/** * Check if all permissions are granted or not *///from w w w .ja v a 2 s . c om @TargetApi(Build.VERSION_CODES.M) private void askPermission() { ArrayList<String> permList = new ArrayList<>(); Context context = getApplicationContext(); if (context .checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) permList.add(Manifest.permission.ACCESS_FINE_LOCATION); if (context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) permList.add(Manifest.permission.READ_PHONE_STATE); if (context.checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) permList.add(Manifest.permission.READ_EXTERNAL_STORAGE); if (context.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) permList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); //Check if some permission are needed if (permList.size() > 0) { String[] permArray = new String[permList.size()]; int i = 0; for (String perm : permList) { permArray[i++] = perm; } ActivityCompat.requestPermissions(this, permArray, PERMISSION_REQUEST_CODE); } if (!hasUsageStatsPermission(this)) { startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); } }
From source file:com.farmerbb.taskbar.MainActivity.java
private void proceedWithAppLaunch(Bundle savedInstanceState) { setContentView(R.layout.main);//from ww w . j a va 2s.c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setCustomView(R.layout.switch_layout); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); } theSwitch = (SwitchCompat) findViewById(R.id.the_switch); if (theSwitch != null) { final SharedPreferences pref = U.getSharedPreferences(this); theSwitch.setChecked(pref.getBoolean("taskbar_active", false)); theSwitch.setOnCheckedChangeListener((compoundButton, b) -> { if (b) { if (U.canDrawOverlays(this)) { boolean firstRun = pref.getBoolean("first_run", true); startTaskbarService(); if (firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !U.isSystemApp(this)) { ApplicationInfo applicationInfo = null; try { applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0); } catch (PackageManager.NameNotFoundException e) { /* Gracefully fail */ } if (applicationInfo != null) { AppOpsManager appOpsManager = (AppOpsManager) getSystemService( Context.APP_OPS_SERVICE); int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName); if (mode != AppOpsManager.MODE_ALLOWED) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(R.string.pref_header_recent_apps) .setMessage(R.string.enable_recent_apps) .setPositiveButton(R.string.action_ok, (dialog, which) -> { try { startActivity( new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); U.showToastLong(MainActivity.this, R.string.usage_stats_message); } catch (ActivityNotFoundException e) { U.showErrorDialog(MainActivity.this, "GET_USAGE_STATS"); } }).setNegativeButton(R.string.action_cancel, null); AlertDialog dialog = builder.create(); dialog.show(); } } } } else { U.showPermissionDialog(MainActivity.this); compoundButton.setChecked(false); } } else stopTaskbarService(); }); } if (savedInstanceState == null) { if (!getIntent().hasExtra("theme_change")) getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit(); else getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit(); } if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) { final SharedPreferences pref = U.getSharedPreferences(this); if (!pref.getBoolean("dont_show_uninstall_dialog", false)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message) .setPositiveButton(R.string.action_uninstall, (dialog, which) -> { pref.edit().putBoolean("uninstall_dialog_shown", true).apply(); try { startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID))); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } }); if (pref.getBoolean("uninstall_dialog_shown", false)) builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit() .putBoolean("dont_show_uninstall_dialog", true).apply()); AlertDialog dialog = builder.create(); dialog.show(); dialog.setCancelable(false); } if (!pref.getBoolean("uninstall_dialog_shown", false)) { if (theSwitch != null) theSwitch.setChecked(false); SharedPreferences.Editor editor = pref.edit(); String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID); if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) { editor.putString("icon_pack", BuildConfig.APPLICATION_ID); } else { U.refreshPinnedIcons(this); } editor.putBoolean("first_run", true); editor.apply(); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); if (shortcutManager.getDynamicShortcuts().size() == 0) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(this, StartTaskbarActivity.class); intent.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar") .setShortLabel(getString(R.string.start_taskbar)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent) .build(); Intent intent2 = new Intent(Intent.ACTION_MAIN); intent2.setClass(this, ShortcutActivity.class); intent2.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode") .setShortLabel(getString(R.string.pref_header_freeform)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform)) .setIntent(intent2).build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2)); } } }
From source file:arun.com.chromer.settings.lookandfeel.PersonalizationPreferenceFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void requestUsagePermission() { new MaterialDialog.Builder(getActivity()).title(R.string.permission_required) .content(R.string.usage_permission_explanation_appcolor).positiveText(R.string.grant) .onPositive((dialog, which) -> getActivity() .startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS))) .dismissListener(dialog -> dynamicAppPreference.setChecked(Utils.canReadUsageStats(getContext()))) .show();// ww w . jav a 2s.c om }
From source file:com.tomer.alwayson.SettingsFragment.java
@Override public boolean onPreferenceChange(final Preference preference, Object o) { if (preference.getKey().equals("watchface_clock")) { int value = Integer.parseInt((String) o); if (value > 2) { if (Globals.ownedItems != null) { if (Globals.ownedItems.size() > 0) { return true; } else { PreferencesActivity.quicklyPromptToSupport(getActivity(), Globals.mService, rootView); return false; }/* w w w. j av a2 s . co m*/ } else { PreferencesActivity.quicklyPromptToSupport(getActivity(), Globals.mService, rootView); } } else { return true; } } prefs.apply(); Utils.logDebug("Preference change", preference.getKey() + " Value:" + o.toString()); if (preference.getKey().equals("notifications_alerts")) { if ((boolean) o) return checkNotificationsPermission(context, true); return true; } if (preference.getKey().equals("persistent_notification") && !(boolean) o) { Snackbar.make(rootView, R.string.warning_1_harm_performance, 10000) .setAction(R.string.action_revert, new View.OnClickListener() { @Override public void onClick(View v) { ((CheckBoxPreference) preference).setChecked(true); restartService(); } }).show(); restartService(); } if (preference.getKey().equals("enabled")) { restartService(); } if (preference.getKey().equals("proximity_to_lock")) { if (Shell.SU.available() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return true; else { DevicePolicyManager mDPM = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); final ComponentName mAdminName = new ComponentName(context, DAReceiver.class); if ((mDPM != null && mDPM.isAdminActive(mAdminName))) { return true; } new AlertDialog.Builder(getActivity()) .setTitle(getString(android.R.string.dialog_alert_title) + "!") .setMessage(getString(R.string.warning_7_disable_fingerprint)) .setPositiveButton(getString(android.R.string.yes), (dialogInterface, i) -> { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.settings_proximity)); startActivityForResult(intent, DEVICE_ADMIN_REQUEST_CODE); }).setNegativeButton(getString(android.R.string.no), (dialogInterface, i) -> { dialogInterface.dismiss(); }).show(); return false; } } if (preference.getKey().equals("startafterlock") && !(boolean) o) { Snackbar.make(rootView, R.string.warning_4_device_not_secured, 10000) .setAction(R.string.action_revert, new View.OnClickListener() { @Override public void onClick(View v) { ((CheckBoxPreference) preference).setChecked(true); } }).show(); } if (preference.getKey().equals("doze_mode") && (boolean) o) { if (Shell.SU.available()) { if (!DozeManager.isDumpPermissionGranted(context)) DozeManager.grantPermission(context, "android.permission.DUMP"); if (!DozeManager.isDevicePowerPermissionGranted(context)) DozeManager.grantPermission(context, "android.permission.DEVICE_POWER"); return true; } Snackbar.make(rootView, R.string.warning_11_no_root, Snackbar.LENGTH_LONG).show(); return false; } if (preference.getKey().equals("camera_shortcut") || preference.getKey().equals("google_now_shortcut")) { try { if (!hasUsageAccess()) { Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS); PackageManager packageManager = getActivity().getPackageManager(); if (intent.resolveActivity(packageManager) != null) { startActivity(intent); } else { Toast.makeText(context, "Please grant usage access permission manually for the app, your device can't do it automatically.", Toast.LENGTH_LONG).show(); } return false; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } if (preference.getKey().equals("battery_saver")) if ((boolean) o) { ((TwoStatePreference) findPreference("doze_mode")).setChecked(true); setUpBatterySaverPermission(); } return true; }
From source file:nu.yona.app.ui.YonaActivity.java
/** * Show permission alert to user on start of application if permission is not granted. *//* w w w . j av a2 s. c om*/ private void showPermissionAlert() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.app_usage_permission_title)); builder.setMessage(getString(R.string.app_usage_permission_message)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { isToDisplayLogin = false; startActivityForResult(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS), MY_PERMISSIONS_REQUEST_PACKAGE_USAGE_STATS); } }); builder.setCancelable(false); builder.create().show(); }