Android: Set App as Device Owner With Accounts Already Set


  • This procedure will delete your user accounts on your device
  • Requires Root Access

To set an app as a device owner with a use account already set you will need to delete your user then set it.

$adb shell dpm set-device-owner com.test.my_device_owner_app/.MyDeviceAdminReciever

Running this command will fail if device is already provisioned.  In shell run the following commands to set an app as the device owner for a device that is already provisioned.

*NOTE: THIS WILL DELETE YOUR USER ACCOUNTS – I have only done this on devices that I didn’t care about the user accounts at all on.

adb shell
rm -fr /data/system/users
dpm set-device-owner com.test.my_device_owner_app/.MyDeviceAdminReciever

Side Note: This is an awesome post with more information here

PHP Get variables in Javascript

  • March 25, 2013

You can get the PHP get variables from javascript using the following function:

            function $_GET(variable) {
                var query =;
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return unescape(pair[1]);
                return false;

This will grab variables in the url such as

How to fix error while loading shared libraries: when installing GNUPG

I was trying to install GNU Privacy Gaurd and ran into this error on the make.

gnupg ../../g10/gpg2: error while loading shared libraries: cannot open shared object file: No such file or directory

I was able to fix this by running the following command:

ldconfig -v

This may not work for everyone but I thought I would put this out there in case someone else runs into this issue.

How to safely unregister Android ContentObserver

  • February 20, 2013

To save system resources ContentObservers need to be safely unregistered when no longer in use.  The best way to do this is the following.

try {
} catch (IllegalStateException ise) {
	// Do Nothing.  Observer has already been unregistered.

As of Android 4.1.2, there is no method to check whether the observer is registered or not.  Therefore we use the try-catch method to catch situations where the observer has already been unregistered.  This sub-routine will typically be included in the onDestroy() of an activity but can be called anywhere you need it.

Create Dojo Dialog in HTML

  • January 30, 2013

You can create a dojo dialog in html code and using the javascript set when the dialog is shown as following.


First declare your dialog:

<div class=”dijitHidden”>
<div data-dojo-type=”dijit.Dialog” data-dojo-props=”title:’Dialog Title'” id=”dialogId”>
<p><b>This div holds the body of the dialog</b></p>

<button onclick=”dijit.byId(‘dialogId’).hide();”>Ok</button>

To show this dialog use the javascript code as such:


Querying for Presence in Android

  • January 30, 2012

Presence is saved in the Android database for each user.  There is a presence table which stores multiple presences and statuses for each user from each presence source, such as skype, jabber, and gTalk.  The presence is derived from some enumeration which would typically include states such as “availible,” “away,” and “do not disturb”.  The status is the message that the user can enter when setting their status, such as if one sets themselves to away on gTalk they might want to include the following message, “Out to lunch be right back.” Typically we only want the most recent of any presence provider.  Therefore we can query for the presence and the status associated with this user.  NOTE: The following code is for Android 3.0 and beyond.  For 2.x and below, use a managed cursor instead of the cursor loader.

presenceUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, Uri.encode(lookupKey));

String[] presenseProjection = {

cursorLoader = new CursorLoader(

Cursor presenceCursor = cursorLoader.loadInBackground();

if(presenceCursor.moveToFirst()) {
     int presence = presenceCursor.getInt(presenceCursor.getColumnIndex(Contacts.CONTACT_PRESENCE));
     String status = presenceCursor.getString(presenceCursor.getColumnIndex(Contacts.CONTACT_STATUS));

If we want to react to a new presence we can register a ContentObserver on the database.  We should register on the database table instead of the cursor.  If we register on the cursor then the cursor must stay open and that takes up valuable resources and will potentially slow down your application.

ContentObserver statusObserver = new ContentObserver(new Handler()) {
			public void onChange(boolean selfChange) {
				presenceCursor = cursorLoader.loadInBackground();
				// Do what you want with the cursor

		context.getContentResolver().registerContentObserver (presenceUri, true, statusObserver); 

Fragment Sample Code

  • October 13, 2011

Tonight I will be giving a talk on Fragments at the Android Developers Meetup in Dallas.  Here is the sample code for the application I am demoing.  The zip includes the slides I will be speaking on.


Thank you to all that attended.

Hide and show Fragments using a FragmentTransaction

Fragment is a child of Object and not View so one cannot call:


Instead we can use a FragmentTransaction to hide or show a fragment.

From the holder activity or a fragment:

FragmentTransaction ft = getFragmentManager().beginTransaction();

Note that multiple fragments can be hidden or shown before the commit by making multiple calls to ft.hide(…) or…).

This flow will work with all the FragmentTransaction actions; add, remove, show, hide, attach, and detach.

./adb: No such file or directory

  • September 20, 2011

./adb: No such file or directory

This problem shows up on Ubuntu for some users. Most users can fix this by installing the ia32-libs package.

sudo apt-get install ia32-libx

Create links to Android Marketplace: Android

  • August 16, 2010

See the bottom of this link to see how to link to the Android Marketplace.

Click here