Friday, January 10, 2014

Sending Android BOOT_COMPLETED broadcast using adb

It's easy to broadcast an intent to a specific application using adb. For example, if you want your app to run automatically after system is up, you'd want to catch BOOT_COMPLETED intent like this in your manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>

After all those related coding, you can use this to test if everything is set up correctly:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n urdomain.appname/.classname
Note that the classname is the BroadcastReceiver which receives the "android.intent.action.BOOT_COMPLETED" intent. Broadcasting is carried out successfully if you see:
Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED cmp=com.nvidia.cms/.AutoStart } Broadcast completed: result=0

.gitignore for Android application on Eclipse

It's been 4(?) years since I developed my last Android application. I found the following .gitignore file useful for adding a Eclipse Android application project folder to git:

  *.apk *.ap_ *.dex *.class bin/ gen/ # Local config local.properties # others (may need?) proguard/ *.iml *.ipr *.iws .idea/
After adding this ignore file for git, simply 'git init' and you're good to use git for your Android application. It's also possible to directly clone a git repository and use File->Import->Existing Android Code into Workspace in Eclipse.