Android - start application from HW button - android

I need to bind some phone HW button to start my application.
It should be done from the code of the application or when installing it.
Is it possible in Android?

You can't bind an application to a key like creating shortcut keys in desktop applications.
If your app is not running then only way it can be invoked other than manual press on launcher icon, is by Broadcast Receivers only. But no key press is broadcasted in Android.
One way to achieve this by running a Service in foreground which watches for Key Presses and can initiate your app when specific Key combination is pressed. But not recommended because user may not like this.

Declare this in your manifest.xml file
<activity android:name=".youractivity">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter >
</activity>

No, you can't do that as far as I know and more importantly, even if you could, you shouldn't - it would be terribly UX. The user expects the hardware buttons to perform a certain function, overriding that sounds like a very bad idea.
Imagine if any app you would install could just change what your home button does...

Related

How to exit from a kiosk lock down mode after the kiosk application is running as an alternate launcher application?

I have found a way to disable the HOME button using a method found here.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
This will precisely disable HOME button because now the application is run as a separate launcher. Now, I need an exit mechanism for the user to come out from the kiosk app and then roam freely on the device.
I currently use finishAffinity() inorder to exit from the app. But it's not an efficient solution as the app is sometimes comes to foreground even though finishAffinity() is called. Any concrete solutions for this issue ?

Voice Action Activity

Although I'm using Xamarin, I believe this to be a general Android development question. I'm developing an app, let's say "My App," that I'd like to be launched via the launcher and via voice using "Ok Google, start My App."
What I'd like to accomplish is to start MainActivity or VoiceActivity depending on the mode in which my app is launched. I found this blog post https://blog.xamarin.com/add-a-conversation-to-your-android-app-with-voice-interactions/ by James Montemagno but whenever I activate My App via "OK Google" it always starts at MainActivity.
I'm hoping someone can provide pointers on what intent-filters to add in order to accomplish this. Here's what I have so far:
<activity android:icon="#drawable/icon" android:label="My App" android:name="md593b8d625023f6802361dd1b8a6546be5.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="My App" android:name="md593b8d625023f6802361dd1b8a6546be5.VoiceActivity">
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
</activity>
I've also read older documentation/reports of apps needing to be made publicly available in the Google Play store to be indexed before "Ok Google" works correctly, but it's not clear if those are for custom actions or something as simple as launching an app via voice.
Thanks in advance for any insight you can provide, I've been banging my head trying to figure out what should be seemingly very easy...
Thanks,
Ryan

intent-filter for knowing when some app is being opened?

I would like to know which intent-filter use for listen when some app is being opened from my BroadcastReceiver.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
Android OS doesn't allow this behavior. No broadcast will be sent out when a particular app is opened.
However, you can have a service that is constantly running in the background and in that service you can use the ActivityManager to get a list of the current open apps. Based on that info, you can start your activity. This is a work around.
There is no system broadcast sent out "when some app is being open", for privacy and security reasons.

uninstall Application Password Protected

How to start an Activity or an IntentService before an application will be uninstalled by the user who has earlier installed the app on there device?
One way to achieve what you want would include the following steps:
(temporarily) rooting the device
converting the app in question into a system app (e.g. using Titanium Backup ★ root, but there are also other apps helping you with this step)
unroot the device again
As the app now resides in read-only space (/system), the user cannot delete it without either rooting the device or flashing a ROM -- which of course could be done, but it's a higher inhibition threshold at least.
There is no such thing as impossible with computers. There is only difficult and highly improbable to happen anytime soon. This is a fact not an opinion. Often someone says "impossible" and there is someone interrupting them saying "Just did it.".
You cannot prefend an user removing an application.
The DELETE intent will be send when the user requests to uninstall.
The PackageManager will receive this intent and start uninstalling the application.
So, without any Android modifications, you cannot add an password.
You have to use Intent filter called "android.intent.action.DELETE" in the AndroidManifest.xml
Like below
<activity
android:name=".Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
This will call the activity.

Android HoneyComb Registering Home Activity

Last year I developed an app on a Xoom running Honeycomb 3.0. When running on that device the following code from the manifest worked.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.BROWSER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
As you will know this registers my app (specifically, the Activity) to listen for "Home Intents." This worked fine and after the first time I could set my app as the default activity for this action.
Now I have installed the same app onto a Samsung Galaxy Tab running Honeycomb 3.1 and this functionality no longer works, no matter what state the app is in, or how many times it has been opened.
Is this intentional? Is this a Samsung only issue? Most importantly - can I regain the functionality I used to get on the Xoom?
P.S My app is completely legitimate in its intentions and has a perfectly understandable reason to want to replace the Home app.
Get rid of:
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSER"/>
and see if that helps. Also, try the Home sample app found in your SDK. It uses the following <intent-filter>:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
My solution was to install, and then uninstall the sample Home app for Android 3.1.
Pressing home now allows a choice between my app and the default Launcher app.
My app remains unchanged.
I had this same problem on an ASUS tablet. I believe the problem was because Launcher was set as the default app for the Home button (i.e., I pressed the home button, got the popup that asks which application I wanted to use, clicked the 'Use by default for this action' checkbox at the bottom of the pop-up, then chose Launcher).
You can fix the problem by going to Settings->Applications, choosing the Launcher, then clicking on the Clear Defaults button.
I gather the reason the sample Home app does the trick is because it clears the defaults itself (how, I don't know, but I know it's not done by setting categories in the intent-filter).

Categories

Resources