简体   繁体   中英

How can I replace an app which receive an intent send by an physical button in android 4.4?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM