我有一个应用程序,一旦用户拨打一个号码就会激活它的活动 - 例如一个数字“6”。我的问题是:一旦从键盘拨打号码,我该如何激活我的应用或应用中的活动?
答案 0 :(得分:1)
听起来你正在寻找“密码”功能。它不会让你听一个号码(我不相信这是可能的),但它允许应用程序使用#等代码启动#123456##< / em>的
您可以注册一个BroadcastReceiver来监听清单中的密码,如下所示:
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data android:scheme="android_secret_code" android:host="123456"/>
</intent-filter>
</receiver>
你的BroadcastReceiver可能看起来像这样:
public class MyBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClass(context, MyBroadcastReceiver.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}