1

I'm a new developer of Android app. I have a smartphone with Android 4.4 and it has an extra physical button. when you press the button, it sends an intent, and one app named "AAA" receive this intent and start to run the app.

I need to implement an app "BBB" which replace this app "AAA". As I am a newcomer in the area of developing app android, can anybody tell me the easiest way to replace this app "AAA" with app "BBB"?

thank you.

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
zli91
  • 13
  • 2

1 Answers1

0

If we assume the implementation of this button is similar as Android's Home button, we can use the same approach to override it.

For example, here's an activity declaration with an intent filter to receive a MAIN intent when the Home button is pressed:

<activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:excludeFromRecents="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <!-- The following two intent-filters are the key to set homescreen -->
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>

In case you need, there are plenty of discussions for the Home Button case.

Then, you would need be to figure out what are the action being used for your button and then use a very similar piece of code on your activity declaration.

Community
  • 1
  • 1
RobertoAllende
  • 8,744
  • 4
  • 30
  • 49
  • Hi, Roberto. Thank you for your replay. I get the app works with the button. but when i restart the device, it doesn't work. then i need to reinstall the app, it work again, but after restart, it doesn't work again. Could you tell me how can i do? – zli91 Jun 12 '15 at 13:46
  • Instead of reinstalling, did you try just running the app after reboot ?. If that works, what you need to do is to use RECEIVE_BOOT_COMPLETED action like in http://stackoverflow.com/questions/8277207/how-to-catch-the-system-broadcast-boot-completed-my-program-just-doesnt-work – RobertoAllende Jun 12 '15 at 16:41
  • i'm trying the program, but i doesn't work. i mean, after i reboot the device, i can run the app from launcher, but i can't run it by pressing the button. My app just have an activity of opening a web page. – zli91 Jun 16 '15 at 08:47