Make my app launch when secret code entered?

后端 未结 3 1402
我寻月下人不归
我寻月下人不归 2021-02-02 04:34

How would I make my app launch when a secret code, such as *#*#12345#*#* is entered into the dialer?

I couldn\'t find a solution in the Android docs.

相关标签:
3条回答
  • 2021-02-02 04:52

    Insted broadcast reciever maybe you should register to proper activity intent. For example Intent.ACTION_CALL looks promessing. Problem is how to filter intents to recive only this one specyfic number. I suspect that it would look like this (I'm gesing based on what I've found in documentation):

    <action name=".YourAction">
        <intent-filter . . . >
            <action android:name="android.intent.action.CALL" />
            <!-- data is crutial here, you have to figuire it out exacly yourself -->
            <data android:scheme="tel" android:path="yourSpecyficSecretCode" />
        </intent-filter>
    </action>
    

    Look here and here. Use LogCat to see what exacly intent contatins then you can filter this properly.

    0 讨论(0)
  • 2021-02-02 04:56

    This is how I did it:

    I changed my main activity to have no intent-filters:

    <activity
                android:name=".ParentTrap"
                android:label="@string/title_activity_parent_trap"
                android:theme="@android:style/Theme.Holo" >
            </activity>
    

    I then made a broadcast receiver with the intent filter action: android.provider.Telephony.SECRET_CODE

    I then added data to it. The entire thing is below:

    <receiver android:name=".ParentTrap$Launch" >
                <intent-filter>
                    <action android:name="android.provider.Telephony.SECRET_CODE" />
    
                    <data
                        android:host="(secret code)"
                        android:scheme="android_secret_code" />
                </intent-filter>
            </receiver>
    

    Once done, make a class (I made the Launch class in my main class, extending BroadCast Receiver), then in the onReceive class, fire an intent to launch the activity.

    Then typing *#*#(secret code)#*#* into the dialer will launch the app.

    0 讨论(0)
  • 2021-02-02 05:00

    Create a broadcast receiver with this action:

    • ACTION_NEW_OUTGOING_CALL

    In the extras you find the dialed number.

    Edit: Here is tutorial for broadcast receiver.

    0 讨论(0)
提交回复
热议问题