2012-12-17 42 views
0

我是一名android开发人员。 (初学者)通过拨打号码启动应用程序

我想知道如何通过输入/调用特定的代码(例如智能锁应用程序)来启动应用程序启动,您可以通过调用此代码#000启动它。

回答

1

您可以通过它的完整软件包名称How to start activity in another application?启动应用程序。您可以在您的应用启动器内实现所需的逻辑。像将代码#000绑定到特定的包,如“com.example.android”。

if(code.equals("#000") { 
    intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity")); 
} 
else if{code.equals(#???"){ 
    //another app 
} 
+0

也许我不明白你很好,但我怎么能将代码绑定到特定的包。我的意思是我无法理解你!谢谢。 – Abdo

+0

我编辑了答案 – Taras

+0

看来我没有很好地解释我的问题。我的意思是,当有人试图从Phone应用程序调用特定的代码号码时,我想启动我的应用程序。希望现在很清楚,并且非常感谢你帮助我。 – Abdo

3

你必须使用广播接收器...

public class OutgoingCallReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      Bundle bundle = intent.getExtras(); 

      if(null == bundle) 
        return; 

      String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

      Log.i("OutgoingCallReceiver",phonenumber); 
      Log.i("OutgoingCallReceiver",bundle.toString()); 

      if(code.equals("#000") { 
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity")); 

和Android设备清单

<receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver"> 
        <intent-filter> 
         <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> 
        </intent-filter> 
      </receiver> 
相关问题