@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = getIntent(); int button = intent.getIntExtra(BUTTON_KEY, 0); if(button > 0) { ((TextView)findViewById(R.id.textview)).setText("Button " + button + " is pressed!"); } //Ask permission if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) { Intent permissionIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(permissionIntent, CODE_DRAW_OVER_OTHER_APP_PERMISSION); } }
/** * 打开已安装应用的详情 */ public static void goToInstalledAppDetails(Context context, String packageName) { Intent intent = new Intent(); int sdkVersion = Build.VERSION.SDK_INT; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.fromParts("package", packageName, null)); } else { intent.setAction(Intent.ACTION_VIEW); intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); intent.putExtra((sdkVersion == Build.VERSION_CODES.FROYO ? "pkg" : "com.android.settings.ApplicationPkgName"), packageName); } intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String value = (String)newValue; final Uri uri; if (Settings.System.DEFAULT_NOTIFICATION_URI.toString().equals(value)) { uri = null; } else { uri = Uri.parse(value); } recipients.setRingtone(uri); new AsyncTask<Uri, Void, Void>() { @Override protected Void doInBackground(Uri... params) { DatabaseFactory.getRecipientPreferenceDatabase(getActivity()) .setRingtone(recipients, params[0]); return null; } }.execute(uri); return false; }
@Override public void handleClick() { if (mMode != GravityBoxSettings.ED_DISABLED) { collapsePanels(); // give panels chance to collapse before changing expanded desktop state mHandler.postDelayed(new Runnable() { @Override public void run() { Settings.Global.putInt(mContext.getContentResolver(), ModExpandedDesktop.SETTING_EXPANDED_DESKTOP_STATE, (mExpanded ? 0 : 1)); } }, 800); } super.handleClick(); }
private void refreshLastRescanAction() { String message; boolean clickable = false; switch (NetworkAutoRefresh.getLastError(getActivity())){ case NetworkAutoRefresh.AUTO_RESCAN_ERROR_NO_WIFI: message = getString(R.string.rescan_error_wifi); int wifiPolicy = Settings.System.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_SLEEP_POLICY, Settings.Global.WIFI_SLEEP_POLICY_NEVER); if(wifiPolicy!=Settings.Global.WIFI_SLEEP_POLICY_NEVER&&wifiPolicy!=Settings.Global.WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED) { message += " (" + getString(R.string.rescan_error_wifi_click_for_more_info) + ")"; clickable = true; } break; case NetworkAutoRefresh.AUTO_RESCAN_ERROR_UNABLE_TO_REACH_HOST: message = getString(R.string.rescan_error_server); break; default: message = getTimeFormat(PreferenceManager.getDefaultSharedPreferences(getActivity()).getLong(NetworkAutoRefresh.AUTO_RESCAN_LAST_SCAN, 0)); } getActionById(LAST_RESCAN_ID).setLabel2(message); getActionById(LAST_RESCAN_ID).setEnabled(clickable); if(getGuidedActionsStylist().getActionsGridView()!=null&&getGuidedActionsStylist()!=null) //depending on when it is called getGuidedActionsStylist().getActionsGridView().getAdapter().notifyDataSetChanged(); }
public void updateBacklightTime(int time) { ContentValues values = new ContentValues(1); ContentResolver cr = mcontext.getContentResolver(); Uri blTimeUri = Settings.System.CONTENT_URI; int result; //Log.v("updateBacklightTime", "num:" + time); Settings.System.putInt(cr, Settings.System.SCREEN_OFF_TIMEOUT, time); // Log.v("updateBacklightTime", "putINTOK"); values.put("screen_off_timeout", time); try { result = cr.update(blTimeUri, values, null, null); } catch (Exception e) { result = 0; } // Log.v("Result", "result is:" + result); }
@Override public void startDialPhoneNumber(String number) { Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.fromParts( "tel", number, null)); if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { if (((TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE)) .getSimState() == TelephonyManager.SIM_STATE_READY) { if (Settings.Global.getInt(getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) == 0) { startActivity(phoneIntent); return; } } } Snackbar.make(phoneTextView, R.string.calls_unavailable_error, Snackbar.LENGTH_SHORT).show(); }
public static String getDeviceId(Context context) { String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); if (!TextUtils.isEmpty(androidId)) { String serial = Build.SERIAL; if (!"unknown".equalsIgnoreCase(serial)) { return androidId + serial; } return androidId; } File file = new File(context.getFilesDir(), "deviceId"); file.mkdir(); File[] files = file.listFiles(); if (files.length > 0) { return files[0].getName(); } String id = UUID.randomUUID().toString(); (new File(file, id)).mkdir(); return id; }
private static long doGetId(Application application) { String androidId = Settings.Secure.getString(application.getContentResolver(), Settings.Secure.ANDROID_ID); if (TextUtils.isEmpty(androidId) || "9774d56d682e549c".equals(androidId)) { androidId = PreferencesUtils.getPreferences(application) .getString(Settings.Secure.ANDROID_ID, "0"); } long breventId; try { breventId = new BigInteger(androidId, 16).longValue(); } catch (NumberFormatException e) { breventId = 0; UILog.w("Can't parse " + androidId, e); } if (breventId == 0) { breventId = 0xdeadbeef00000000L | new SecureRandom().nextInt(); PreferencesUtils.getPreferences(application).edit() .putString(Settings.Secure.ANDROID_ID, Long.toHexString(breventId)).apply(); } return breventId; }
/** * app 设置 * * @param context c * @param packageName pn */ public static void showInstalledAppDetails(Context context, String packageName) { Intent intent = new Intent(); final int apiLevel = Build.VERSION.SDK_INT; if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(SCHEME, packageName, null); intent.setData(uri); } else { // 2.3以下,使用非公开的接口(查看InstalledAppDetails源码) // 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。 final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21); intent.setAction(Intent.ACTION_VIEW); intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME); intent.putExtra(appPkgName, packageName); } context.startActivity(intent); }
@NonNull private Intent getSettingsIntent(String packageName) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", packageName, null); intent.setData(uri); return intent; }
private void Recarregar() { //Verifica se há internet if (Utils.haveInternet(getActivity())) { //Carrega as Notícias new DownloadNoticias(getActivity(), mRelativeLayout, mRecyclerView).execute(Utils.getUrlApiNoticia(getActivity())); } else SnackbarManager.show( Snackbar.with(getActivity()) .text("Por favor verifique sua conexão com a Internet") .type(SnackbarType.MULTI_LINE) .actionLabel("CONECTAR") .actionColor(getResources().getColor(R.color.colorAccent)) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) .actionListener(new ActionClickListener() { @Override public void onActionClicked(Snackbar snackbar) { //Inicia as configurações de rede startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); } }) ); }
@Override public void onDestroy() { if (created) { this.unregisterReceiver(batReceiver); Log.d(getClass().getSimpleName(), "Receiver unregistered"); if (wl.isHeld()) { wl.release(); Log.d(getClass().getSimpleName(), "WL released"); } } boolean isEnabled = Settings.System.getInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; if (isEnabled) { Log.d(getClass().getSimpleName(), "Turning airplanemode off"); Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); Intent reload = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); reload.putExtra("state", false); sendBroadcast(reload); } Log.d(getClass().getSimpleName(), "Charge Preserver service stopped"); Toast.makeText(this.getApplicationContext(), "Service has been shutdown", Toast.LENGTH_SHORT).show(); prefEditor.putBoolean("isService", false); prefEditor.commit(); }
public static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); String imei = tm.getDeviceId(); String tmDevice; if(null != imei && !"".equals(imei)) { tmDevice = "^[0]+$"; if(!imei.matches(tmDevice)) { return imei; } } tmDevice = "" + tm.getDeviceId(); String tmSerial = "" + tm.getSimSerialNumber(); String androidId = "" + Settings.Secure.getString(context.getContentResolver(), "android_id"); return (new UUID((long)androidId.hashCode(), (long)tmDevice.hashCode() << 32 | (long)tmSerial.hashCode())).toString(); }
@Override protected void onCreate(Bundle savedInstanceState) { context = this; twitter = TwitterUtil.getTwitterInstance(this); super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar); SettingsFragment fragment = new SettingsFragment(); getFragmentManager().beginTransaction() .replace(android.R.id.content, fragment) .commit(); if (!NotificationService.isNotificationAccessEnabled) { startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)); } }
protected void setAutobrightness(Activity activity, ContentResolver resolver, boolean on) { super.setAutobrightness(activity, resolver, on); // set auto brightness on/off int value = on ? 255 : 128; // auto or middle brightness Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, value); if (!on) { // update slider RangeSetting setting = (RangeSetting) mSetting; setting.value = getPercentValue(value); setting.descr = null; setting.enabled = false; setting.checked = false; setting.updateView(); } // update current view's brightness LayoutParams attrs = mActivity.getWindow().getAttributes(); attrs.screenBrightness = on ? 1f : value / (float) getMaximum(); // request brightness update Window window = mActivity.getWindow(); window.setAttributes(attrs); }
private void initializeDefaultPreference() { if (VERSION.SDK_INT < VERSION_CODES.KITKAT) return; Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); if (Util.isDefaultSmsProvider(getActivity())) { defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled)); defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_change_your_default_sms_app)); } else { Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName()); defaultPreference.setIntent(intent); defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled)); defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_make_signal_your_default_sms_app)); } }
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { for (int grantResult : grantResults) if (grantResult == PackageManager.PERMISSION_DENIED) { new AlertDialog.Builder(this) .setCancelable(false) .setMessage(R.string.permission_denied_dialog_message) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { final Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.parse("package:" + MainActivity.this.getPackageName())); MainActivity.this.startActivity(intent); } }) .show(); break; } }
public static void showInstalledAppDetails(Context context, String packageName) { Intent intent = new Intent(); final int apiLevel = Build.VERSION.SDK_INT; if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(SCHEME, packageName, null); intent.setData(uri); } else { // 2.3以下,使用非公开的接口(查看InstalledAppDetails源码) // 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。 final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21); intent.setAction(Intent.ACTION_VIEW); intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME); intent.putExtra(appPkgName, packageName); } context.startActivity(intent); }
public static boolean canDrawOnSystemLayer(@NonNull Context context, int systemWindowType) { if (isSystemLayer(systemWindowType)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { return Settings.canDrawOverlays(context); } else if (systemWindowType == TYPE_TOAST) { // since 7.1.1, TYPE_TOAST is not usable since it auto-disappears // otherwise, just use it since it does not require any special permission return true; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return Settings.canDrawOverlays(context); } else { return hasSystemAlertPermission(context); } } return true; }
@SuppressWarnings("UnusedReturnValue") private static boolean checkForExcessOpenNetworkAndSave(@NonNull final ContentResolver resolver, @NonNull final WifiManager wifiMgr) { final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks(); sortByPriority(configurations); boolean modified = false; int tempCount = 0; final int numOpenNetworksKept = Build.VERSION.SDK_INT >= 17 ? Settings.Secure.getInt(resolver, Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT, 10) : Settings.Secure.getInt(resolver, Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10); for (int i = configurations.size() - 1; i >= 0; i--) { final WifiConfiguration config = configurations.get(i); if (Objects.equals(ConfigSecurities.SECURITY_NONE, ConfigSecurities.getSecurity(config))) { tempCount++; if (tempCount >= numOpenNetworksKept) { modified = true; wifiMgr.removeNetwork(config.networkId); } } } return !modified || wifiMgr.saveConfiguration(); }
/** * Initialize internal states of this object. * * @param context the context for this application. * @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment. * @return true if this application is an IME and has two or more subtypes, false otherwise. */ public boolean init(final Context context, final PreferenceScreen prefScreen) { mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); mImi = getMyImi(context, mImm); if (mImi == null || mImi.getSubtypeCount() <= 1) { return false; } final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); mSubtypeEnablerPreference = new Preference(context); mSubtypeEnablerPreference.setIntent(intent); prefScreen.addPreference(mSubtypeEnablerPreference); updateSubtypeEnabler(); return true; }
/** * Check if NFC is enabled and display error message when it is not. * This method should be called each time the activity is resumed, because people could change their * settings while the app is open. */ public void checkNFCStatus() { if (mNfcAdapter == null) { // Stop here, we definitely need NFC Toast.makeText(this, R.string.nfc_not_supported_error, Toast.LENGTH_LONG).show(); finish(); return; } // Display a notice that NFC is disabled and provide user with option to turn on NFC if (!mNfcAdapter.isEnabled()) { // Add listener for action in snackbar View.OnClickListener nfcSnackbarListener = new View.OnClickListener() { @Override public void onClick(View v) { thisActivity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); } }; Snackbar nfcDisabledSnackbar = Snackbar.make(findViewById(R.id.coordinator_layout), R.string.nfc_disabled_error_snackbar, Snackbar.LENGTH_INDEFINITE); nfcDisabledSnackbar.setAction(R.string.nfc_disabled_snackbar_action, nfcSnackbarListener); nfcDisabledSnackbar.show(); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_quiz14, container, false); String android_id = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); String deviceId = md5(android_id).toUpperCase(); Log.i("device id=",deviceId); AdView adView = (AdView)view.findViewById(R.id.adViewques14); AdRequest adRequest = new AdRequest.Builder() .addTestDevice(deviceId) .build(); adView.loadAd(adRequest); return view; }
/** * Is Notification Service Enabled. * Verifies if the notification listener service is enabled. * Got it from: https://github.com/kpbird/NotificationListenerService-Example/blob/master/NLSExample/src/main/java/com/kpbird/nlsexample/NLService.java * @return True if eanbled, false otherwise. */ private boolean isNotificationServiceEnabled(){ String pkgName = getPackageName(); final String flat = Settings.Secure.getString(getContentResolver(), ENABLED_NOTIFICATION_LISTENERS); if (!TextUtils.isEmpty(flat)) { final String[] names = flat.split(":"); for (int i = 0; i < names.length; i++) { final ComponentName cn = ComponentName.unflattenFromString(names[i]); if (cn != null) { if (TextUtils.equals(pkgName, cn.getPackageName())) { return true; } } } } return false; }
public static void getAccessibilityStatus(Context context) { long start = System.currentTimeMillis(); try { Set<ComponentName> enabledServices = new HashSet<>(); final String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); final TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':'); colonSplitter.setString(enabledServicesSetting); while (colonSplitter.hasNext()) { final String componentNameString = colonSplitter.next(); final ComponentName enabledService = ComponentName.unflattenFromString(componentNameString); BaseAccessibility.logPrint("getAccessibilityStatus= " + componentNameString + " enabledService=" + (enabledService == null ? false : true)); if (enabledService != null) { enabledServices.add(enabledService); } } ComponentName appstoreComponent = new ComponentName(context, MyAccessibility.class); BaseAccessibility.isEnable.set(enabledServices.contains(appstoreComponent)); BaseAccessibility.logPrint("getAccessibilityStatus status:" + BaseAccessibility.isEnable.get() + " enabledServicesSetting=" + enabledServicesSetting); } catch (Throwable e) { BaseAccessibility.logPrint(e.getMessage()); e.printStackTrace(); } BaseAccessibility.logPrint("getAccessibilityStatus= " + "getAccessibilityStatus cost:" + (System.currentTimeMillis() - start) + ",status:" + BaseAccessibility.isEnable.get()); }
@Override public View createDetailView(Context context, View convertView, ViewGroup parent) throws Throwable { if (mDetails == null) { mDetails = QsDetailItemsList.create(context, parent); mDetails.setEmptyState(R.drawable.ic_qs_location_off, GpsStatusMonitor.getModeLabel(mContext, Settings.Secure.LOCATION_MODE_OFF)); mAdapter = new AdvancedLocationAdapter(context); mDetails.setAdapter(mAdapter); final ListView list = mDetails.getListView(); list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); list.setOnItemClickListener(this); } return mDetails.getView(); }
private void setScreenOffTimeout(int millis) { if (millis == NEVER_SLEEP && mCurrentTimeout != NEVER_SLEEP) { mPreviousTimeout = mCurrentTimeout; } if (mAutoReset && mDefaultTimeout == 0) { mDefaultTimeout = mCurrentTimeout == NEVER_SLEEP ? FALLBACK_SCREEN_TIMEOUT_VALUE : mCurrentTimeout; if (DEBUG) log(getKey() + ": mDefaultTimeout=" + mDefaultTimeout); } mCurrentTimeout = millis; Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, mCurrentTimeout); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_WINDOW_OVERLAY_PERMISSION) { if (android.os.Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(this)) { onSuccess(); } else { onFailure(); } } }
private void getNightMode() { int val = Settings.Secure.getInt(activity.getContentResolver(), TWILIGHT_MODE, 0); switch (val) { case 0: mNightModeAuto = false; mNightModeOverride = false; night_mode_auto.setChecked(false); night_mode_override.setChecked(false); break; case 1: mNightModeAuto = false; mNightModeOverride = true; night_mode_auto.setChecked(false); night_mode_override.setChecked(true); break; case 2: mNightModeAuto = true; mNightModeOverride = false; night_mode_auto.setChecked(true); night_mode_override.setChecked(false); break; case 4: mNightModeAuto = true; mNightModeOverride = true; night_mode_auto.setChecked(true); night_mode_override.setChecked(true); break; } }
/** * 获取 ANDROID_ID */ public static String getAndroidId(Context context) { String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); if (Log.isPrint) { Log.i(TAG, "ANDROID_ID :" + androidId); } return androidId; }
/** * 开启亮度自动调节 * * @param activity */ public static void startAutoBrightness(Activity activity) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + activity.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(intent); } else { //有了权限,具体的动作 Settings.System.putInt(activity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); } }
/** * On create, check if the user has location enabled. * Obtain the MapFragment and get notified when the map is ready to be used. * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the MapFragment and get notified when the map is ready to be used. MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); options = (Button) findViewById(R.id.map_options); mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); try { toDisplayAL = (ArrayList<Markers>) getIntent().getExtras().getSerializable("toDisplay"); } catch (Exception e) { // no events to display } // If GPS (location) is not enabled, User is sent to the settings to turn it on! service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!enabled) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } else { getDeviceLoc(); } options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); }
private void updateNotificationPreferenceState() { if (mNotificationPreference == null) { mNotificationPreference = initVolumePreference(KEY_NOTIFICATION_VOLUME, AudioManager.STREAM_NOTIFICATION, com.android.internal.R.drawable.ic_audio_ring_notif_mute); } if (mVoiceCapable) { final boolean enabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1; if (mVolumeLinkNotificationSwitch != null) { mVolumeLinkNotificationSwitch.setChecked(enabled); } } }
@TargetApi(16) private void doOnJellybean(Intent intent) { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter == null) { return; } if (nfcAdapter.isEnabled()) { intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); } else { intent.setAction(Settings.ACTION_NFC_SETTINGS); } }
public int getBacklightTime() { int Time = 0; ContentResolver cr = mcontext.getContentResolver(); try { Time = Settings.System.getInt(cr, Settings.System.SCREEN_OFF_TIMEOUT); } catch (SettingNotFoundException snfe) { //Log.d(tag,"error()"); } return Time; }
/** * Opens GPS settings to allow user turn GPS on. */ @Override public void onGPS() { Intent gpsIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); startActivityForResult(gpsIntent, gpsReqCode); }
private static String getCallMethodGetGlobal() { try { return Settings.CALL_METHOD_GET_GLOBAL; } catch (LinkageError e) { Log.w(TAG, "Can't find Settings.CALL_METHOD_GET_GLOBAL"); return "GET_global"; } }
void goToNotificationServiceSettings(DrawerMenuItemViewHolder holder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { return; } boolean enabled = NotificationListenerService.getInstance() != null; boolean checked = holder.getSwitchCompat().isChecked(); if ((checked && !enabled) || (!checked && enabled)) { startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)); } }
private void updateState() { int state = Settings.System.getInt(mActivity.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0); boolean isEnabled = state == 1; Setting setting = mSetting; setting.checked = isEnabled; setting.descr = mActivity.getString(isEnabled ? R.string.txt_status_turned_on : R.string.txt_status_turned_off); setting.updateView(); }