当输入秘密代码,例如*#*#12345#*#*
到拨号应用程序时,我该如何使我的应用程序启动?
我在Android文档中找不到解决方案。
当输入秘密代码,例如*#*#12345#*#*
到拨号应用程序时,我该如何使我的应用程序启动?
我在Android文档中找不到解决方案。
<activity
android:name=".ParentTrap"
android:label="@string/title_activity_parent_trap"
android:theme="@android:style/Theme.Holo" >
</activity>
接下来,我使用意图过滤器操作创建了一个广播接收器:android.provider.Telephony.SECRET_CODE
然后我向其中添加了数据。以下是整个内容:
<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>
完成后,创建一个类(我在我的主类中创建了Launch类,扩展了BroadCast接收器),然后在onReceive类中,发送意图启动活动。
然后在拨号键盘中输入*#*#(秘密代码)#*#*
将启动该应用程序。
与其使用广播接收器,也许你应该注册到适当的活动意图中。例如Intent.ACTION_CALL看起来很有前途。问题是如何过滤意图以仅接收这个特定号码。我猜测它会像这样(根据我在文档中找到的内容猜测):
<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>