Android的,是否有可能运行从拨号器的应用程序?有可能、应用程序、拨号器、Android

2023-09-05 23:58:36 作者:似水往昔浮流年_,

我需要(如果可能),当用户输入code到的能力添加到我的项目要运行诸如#的 1234 的#拨号器。我不知道这是可能的。目前,当我从午饭应用程序文件夹我的应用程序启动,但只是为了好玩,我想知道我可以吃午饭也可以用code?

I need (if its possible) to add an ability to my project to be run when user enters a code such as #1234# in dialer. I'm not sure it is possible. Currently when i lunch my app from application folder it starts but just for fun i want to know can i lunch it with a code?

感谢你这么多的帮助。

推荐答案

您可以通过拨号器启动应用程序的活动类,但对你的应用程序应该在后台运行。对,你应该执行哪些扩展到了BroadcastReceiver的类。按照这个参考code。

You can start your application activity class by dialer but for that your app should running in background. for that you should implement a class which extends to BroadcastReceiver. follow this reference code.

public class Example extends BroadcastReceiver 
{

    @Override
    public void onReceive(Context context, final Intent intent) {

      if (intent.getAction().equals(android.intent.action.NEW_OUTGOING_CALL)) {
       String phoneNumber = intent.getExtras().getString( android.intent.extra.PHONE_NUMBER );

         if(phoneNumber.equals("#1234#")) { 
            Intent intent1 = new Intent(context , YourActivity.class);
            intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            context.startActivity(intent1);
       }

      }

    }

}