preferences

Get preferred screen brightness in Android

懵懂的女人 提交于 2019-11-28 17:36:47
How do you get the preferred screen brightness in Android? To change the screen brightness I use WindowManager.LayoutParams.screenBrightness . According to the documentation: This can be used to override the user's preferred brightness of the screen. A value of less than 0, the default, means to use the preferred screen brightness. 0 to 1 adjusts the brightness from dark to full bright. When screenBrightness is less than 0 I would like to start with the preferred screen brightness. How can I get this value? I'll try to answer because I already searched for this some time ago. My short answer

iPhone - How to detect if a key exists in NSUserDefaults standardUserDefaults

倖福魔咒の 提交于 2019-11-28 16:44:52
问题 Using NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; , I use calls like BOOL boolFromPrefs = [defaults boolForKey:@"theBoolKey"]; To get a saved BOOL value. If the key is not found, NO is returned (default behaviour of boolForKey). But... NO can be a saved setting. Same thing for intForKey So how can I test if a key exists before trying to get its value ? 回答1: Do it the right way and register default values. NSDictionary *userDefaultsDefaults = @{ @"SomeKey": @NO, @

Shared Preferences reset when the app is force closed or crashes

拜拜、爱过 提交于 2019-11-28 13:25:52
I have noticed that my app's SharedPreferences are completely reset if the app is force closed or is killed by the system for some reason. Obviously, yes, I should avoid having a crash in the first place but it does happen. If it does happen, the user shouldn't loss all of their settings and other data stored with the Preferences. I found this thread on Google Groups but they couldn't solve it. Anyone have any insight into why or how this happens and if there is a way to prevent it? Also, fyi I have seen this on a 2.1 and a 2.2 device. It will happen on every crash, not just some of them.

Android: String set preference is not persistent

别等时光非礼了梦想. 提交于 2019-11-28 12:49:22
I have a problem with storing string set preference. I have these utility methods for storing: public static void putStringSet(SharedPreferences pref, Editor e, String key, Set<String> set) { if (Utils.isApiLevelGreaterThanGingerbread()) { // e.remove(key); // I tried to remove it here e.putStringSet(key, set); } else { // removes old occurences of key for (String k : pref.getAll().keySet()) { if (k.startsWith(key)) { e.remove(k); } } int i = 0; for (String value : set) { e.putString(key + i++, value); } } } public static Set<String> getStringSet(SharedPreferences pref, String key, Set<String>

How to add preference of Custom Input method to Android Settings app?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 12:41:45
Recently I've started to develop Android Soft Keyboard and got some problem with preferences. How to add a preferences to Android setting app? I've searched almost all the source code of AnySoftKeyboard, but haven't found anything what would add them to Settings app. I'm placing a link to show what I meant: http://code.google.com/p/softkeyboard/wiki/Settings (first picture from begin) Thank you P.S. Sorry for my bad english.. I've found it myself: in XML of input method you need to put android:settingsActivity tag with link to your PreferenceActivity class: Example Here is an example: set

Preferences without deprecated methods

家住魔仙堡 提交于 2019-11-28 12:14:34
I'm trying to (correctly) implement a preferences screen, but the problem is that all the methods used to read preferences from xml files are deprecated (or I just don't recognize them). The official sample code on the dev site ( PreferenceActivity ) uses deprecated methods. Has anyone found out a way to implement a preferences screen with an xml file but without using either: addPreferencesFromResource(int) or findPreference(CharSequence)? Or have the methods just been marked deprecated without implementing the alternative yet? EDIT: Developing for Android version 2.1 Why its deprecated and

Writing Eclipse plugin to modify Editor Preferences

蓝咒 提交于 2019-11-28 11:51:46
问题 I'd like to develop a plugin (tool bar buttons) for Eclipse CDT where users can easily switch between 8 and 4 spaces tabs and turn on/off soft tabs. (Why bother you asked? Thanks to the coding guideline in my org for tabbing difference between C/C++ legacy and new codes) I managed to create toolbar buttons but I couldn't find information to modify Editor Preferences (The ones you normally find in Workspace preferences General->Editors->Text Editors). The question 4587572 seems to cover a bit

Android: No Activity found to handle Intent error? How it will resolve

泄露秘密 提交于 2019-11-28 07:13:16
No Activity found to handle Intent error? How it will resolve. Preference customPref = (Preference) findPreference("DataEntryScreen"); customPref .setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent i = new Intent("com.scytec.datamobile.vd.gui.android.AppPreferenceActivity"); startActivity(i); return true; } }); Add the below to your manifest: <activity android:name=".AppPreferenceActivity" android:label="@string/app_name"> <intent-filter> <action android:name="com.scytec.datamobile.vd.gui.android.AppPreferenceActivity

Android shared preferences not saving

时光怂恿深爱的人放手 提交于 2019-11-28 07:11:50
I've created an Android live wallpaper and i'm trying to let a user choose an image from their phone and apply it as a background image, but when I launch the activity that start the intent to pick the images, my shared preferences don't seem to save properly. Below is my onCreate method of the activity I start when the users presses the preference button, and the onActivityResult which gets the path of the image on the device (all that seems to work). The println after I commit the preferences prints out nothing. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Android: launch a custom Preference from a PreferenceActivity

守給你的承諾、 提交于 2019-11-28 06:35:43
I would like to be able launch a 2nd Preference screen from my PreferenceActivity. And in the 2nd Preference screen I'd like to use a predefined layout from xml. So, I have two questions: How do I use an xml layout as the layout view of a Preference? How do I add this custom preference to a PreferenceActivity such that launched when tapped? Thank you *EDIT in response to alibi I am trying to launch an activity from a preference screen, by declaring the activity to be launched in xml. This causes this exception: 04-01 19:04:37.962: ERROR/AndroidRuntime(8061): android.content