Posts

Is there a unique Android device ID?

Do Android devices have a unique ID, and if so, what is a simple way to access it using Java? Settings.Secure#ANDROID_ID  returns the Android ID as an  unique for each user  64-bit hex string. import android . provider . Settings . Secure ; private String android_id = Secure . getString ( getContext (). getContentResolver (), Secure . ANDROID_ID );

Stop EditText from gaining focus at Activity startup

I have an  Activity  in Android, with two elements: EditText ListView When my  Activity  starts, the  EditText  immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. I tried: EditText . setSelected ( false ); No luck. How can I convince the  EditText  to not select itself when the  Activity  starts? Excellent answers from Luc and Mark however a good code sample is missing. Adding the tag  android:focusableInTouchMode="true" to  <LinearLayout> like the following example will fix the problem. <!-- Dummy item to prevent AutoCompleteTextView from receiving focus --> <LinearLayout android:focusable = "true" android:focusableInTouchMode = "true" android:layout_width = "0px" android:layout_height = "0px" /> <!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component to prevent the dummy from...

Proper use cases for Android UserManager.isUserAGoat()?

I was looking at the new APIs introduced in  Android 4.2 . While looking at the  UserManager  class I came across the following method: public boolean isUserAGoat () Used to determine whether the user making this call is subject to teleportations. Returns whether the user making this call is a goat. From their  source , the method used to return  false  until it was changed in API 21. /** * Used to determine whether the user making this call is subject to * teleportations. * @return whether the user making this call is a goat */ public boolean isUserAGoat () { return false ; } It looks like the method has no real use for us as developers. Someone has previously stated that it might be an  Easter egg . In API 21 the implementation was changed to check if there is an installed app with the package  com.coffeestainstudios.goatsimulator /** * Used to determine whether the user making this call is subject to * teleportat...

Close/hide the Android Soft Keyboard

I have an  EditText  and a  Button  in my layout. After writing in the edit field and clicking on the  Button , I want to hide the virtual keyboard. I assume that this is a simple piece of code, but where can I find an example of it? Correct:  To help clarify this madness, I'd like to begin by apologizing on behalf of all Android users for Google's downright ridiculous treatment of the soft keyboard. The reason there are so many answers, each different, for the same simple question because this API, like many others in Android, is horribly designed. I can think of no polite way to state it. I want to hide the keyboard. I expect to provide Android with the following statement:  Keyboard.hide() . The end. Thank you very much. But Android has a problem. You must use the  InputMethodManager  to hide the keyboard. OK, fine, this is Android's API to the keyboard. BUT! You are required to have a  Context  in order to get access...