0

I am an android developer. (beginner)

And I want to know how can I make my application launch by entering/calling a specific code number (from the same device), such as smart lock application, you can launch it by calling this code #000.

Abdo
  • 131
  • 1
  • 8

2 Answers2

3

You have to use Broadcast Receiver...

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"));

And Your Android Manifest

<receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver"> 
                    <intent-filter> 
                        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
                    </intent-filter> 
            </receiver>
GK_
  • 1,212
  • 1
  • 12
  • 26
1

You can launch application by it's full package name How to start activity in another application?. You can implement desired logic inside your app-launcher. like bind a code #000 to a specific package like "com.example.android".

if(code.equals("#000") {
     intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
}
else if{code.equals(#???"){
     //another app
}
Community
  • 1
  • 1
Taras
  • 2,526
  • 3
  • 33
  • 63
  • Maybe I didn't understand you well, but how can I bind a code to a specific package. I mean I couldn't understand you! Thank you. – Abdo Dec 17 '12 at 13:31
  • It seems that I didn't explain my question very well. I meant that I want to launch my application when somebody trying to call a specific code number from Phone application. Hopefully It's clear now, and thank you for trying to help me. – Abdo Dec 17 '12 at 13:41
  • @user1843769 I think it's impossible. – Taras Dec 17 '12 at 14:09
  • It isn't impossible and I found a way to do that. Thank you for your trying to help me. – Abdo Dec 19 '12 at 20:16
  • @user1843769 can you share with your investigations? – Taras Dec 20 '12 at 08:12