Change mode of the getDefaultPreference file in Android - android

I am using a PreferenceActivity to save some user preferences.
I want to access the default Preference file from outside the app for debugging purposes.
How can I change the defaultSharedPreferences file from private to public mode?
And also what is the default name of that defaultSharedPreference file?
[EDIT]
One negative vote that means something is wrong with the question.
At least, do let me know whats wrong!
That would be less cruel and not discouraging for a newbie like me :)

In the DDMS (or its equivalent, in Android Studio), the path to your preference file is /data/data/your.app.name/shared_prefs/your.app.name_preferences.xml.
You can export it, modify it, and even reimport it (at your own risk!).
EDIT
The path is correct, the file name might vary.
Sorry, I wasn't pointing the xml file, while taking the screen shot.
But it's there.

Related

Try to decode random #Variant string from an android studio emulator

Just a quick question ig. I am currently trying something with android studio's virtual devices and i need to edit a parameter in one of the emulator files.
The path to this file is normaly {HomeDir}\.android\avd\name_of_virtual_device.avd\AVD.conf
The content of the file looks like this:
[perAvd]
battery\charge_level=100
loc\latitude=37.422
virtualscene\posters=#Variant(\0\0\0\b\0\0\0\x2\0\0\0\b\0w\0\x61\0l\0l\0\0\0\n\0\0\0\xa0\0\x43\0:\0/\0U\0s\0\x65\0r\0s\0/\0M\0\x61\0x\0i\0m\0i\0l\0i\0\x61\0n\0\x42\0r\0\x61\0u\0n\0/\0P\0i\0\x63\0t\0u\0r\0\x65\0s\0/\0{\0\x36\0\x44\0\x37\0\x43\0\x30\0\x33\0\x37\0\x42\0-\0\x39\0\x34\0\x37\0\x43\0-\0\x34\0\x37\0\x33\0\x37\0-\0\x41\0\x44\0\x30\0\x41\0-\0\x45\0\x36\0\x41\0\x45\0\x43\0\x37\0\x37\0\x37\0\x43\0\x44\0\x34\0\x43\0}\0.\0p\0n\0g\0.\0j\0p\0g\0\0\0\n\0t\0\x61\0\x62\0l\0\x65\0\0\0\n\xff\xff\xff\xff)
virtualscene\tv_animation=false
loc\longitude=-122.084
loc\altitude=5
loc\velocity=0
loc\heading=0
If you know your way arround the avd manager of android studio and emulated devices you should note pretty quickly that this file contains some of the advanced settings that you normaly can set via the menu of your emulated device. Now my question is since i need to edit the virtualscene\posters param which encoding is this. I mean it looks like hex but it isn't. It also contains like png/jpg at the end of the string looking like this .\0p\0n\0g\0.\0j\0p\0g. But i cant figure out which encoding this is
Hope someone can help
That looks like it is probably a QSettings configuration file. This class saves a program's settings to a .conf or .ini file and encodes data like that. It allows it to later read the data back in using QVariant

Android R file constants not auto-updating

I've searched high and low for people with the same question but have only found some variations (i.e. R file not generated at all) that don't help. I'm VERY new to Android development (day one, actually) but from some tutorials I've been reading, this behavior is unexpected. Basically, let's say I create a TextView in my activity's XML file and give it an appropriate android:id. I save the file (and all other files), but if I try to use findViewById in my Java file, the R.id.[view name] is not listed (and displays an error if I manually type it in). If I do a "Build Project," it works, but to have to run the Build command upon creation of every new component will be a huge burden! Has anyone else experienced this or have ideas on why it's happening? Thanks in advance!
If everything else you mentioned is correct, then the only way for you to NOT get the proper R variables is that you might be importing "android.R;" file in stead of your actual R file "your.package.R" which contains the variables you are looking for.
Regards!
You may have to tell your IDE to automatically rebuild changes you make. For example, in Eclipse this would be in: Window > Preferences > General > Workspace. Make sure Build automatically is checked.

Android add new image gives error

This might seems silly but seriously I don't even know why it reacts that way. I am using eclipse JUNO, and I just trying out simple program enables me to put an image inside the layout after my real program said it have the error.
The project shows the error icon but when looking all in the subs-project like the class, layout everything, it is crystal clear. You can see it like the picture above.
I have making an android project before I am updating the adt and stuff. Before this, all I do just put any picture(s) I want in any folder drawable. I believe this is the right step and I know I do the same thing in here but it have issue with it. I even search on the basic tutorial how to put the image and it did the same why I did.
Does anyone knows what had happen here?
Android dont allow image names to contain capital letters in drawable folder change the name to contain only small letters
Capital letters , and some symbols are not allowed to be in the name of the png file , update the name of the png file , . make it in smaall letters
As per user inazaruk's answer, Hence the reason for not using special characters inside file names, as they can no be used in Java names.
As for capital letters, I guess that's to avoid one little problem in Windows vs. Linux environment. That's because Linux thinks that Icon.png and icon.png are different files, and Windows thinks that Icon.png and icon.png is the same file. So anyone using Linux can create application that is not compilable on Windows.
So, change your Humanpng with human Also don't use the extension png as picture name.
Just check your Problems tab in Eclipse. You can find it from
Window > Show View > Problems.
There you can find the error description.

Creating a file on an Android device

I am new to Android development using eclipse, although not new to software development in general.
For my first real project, I am trying to modify the example SoftKeyboard that is supplied with the SDK. I want to modify one of the keys to act as a function key, when followed by a single letter key it will enter a canned string - performing a macro function.
So far so good. I have the key and graphics modified, and found where to respond. I would like to put the canned strings in an editable Properties file stored where the keyboard can find them.
That is where I'm having trouble. It seems that I can't to create and save a file. I don't know if it's read/write permission problem, whether the keyboard (it runs as a service) is not allowed to create a file, or my code is just plain wrong.
Can someone help me out – point me in the right direction?
Thank you very much.
Barry.
If these are canned files that come with the APK you install to the device and only need to read (not write), you can place them in the assets folder of your project. Then use the resource manager to load them:
Resources resources = getResources();
InputStream moduleSearchTemplateIn = resources.getAssets().open("file/name/here.properties");
If you want to read/write files on the SD card, you'll need to add a permission to your manifest. Though, for this purpose, I'd probably prefer a SQLite table.

Android writing to a text file

I have a text file within my raw folder of my app that I intend to use as a simple way to save settings and then read them back when needed. I can read from this file with using the BufferedReader and what comes with it, but I've tried a few different ways to be able to write to this file and none seem to work.
It seems to me that the problem is I never actually get the file, and I assume this is simply because I don't exactly know how I am supposed to give it the correct directory and file name. I've tried all I could come up with, and I tend to get errors like "No such file or directory exists" or "Read-only file system".
This seems to be a very simple problem relating to me just giving the wrong information, so if anybody could point me in the right direction it would be much appreciated.
Thank you,
Raphy
For saving settings you should use SharedPreferences rather than coming up with a custom solution.
SharedPreferences documentation
Data Storage
I'm not entirely sure you can do that with stuff in the "raw" folder.
One approach would be to use the SharedPreference storage in the API. See in the datastorage section of the docs. It's perfect from what you describe neededing. Another approach would be to put the file on the SDCard and read and write it from there.

Categories

Resources