Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

java - Android. Launch app from Dialer

This is what I have so far but nothing happens when I input this combination in dialer

public class DialReceiver extends BroadcastReceiver
{
    @Override
  public void onReceive(Context context, final Intent intent) {

    if (intent.getAction().equals(android.content.Intent.ACTION_NEW_OUTGOING_CALL)) {
        String phoneNumber = intent.getExtras().getString( android.content.Intent.EXTRA_PHONE_NUMBER );

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

    }

}
}

and in androidmanifest

    <receiver
        android:name=".receiver.DialReceiver"
        android:exported="true"
        android:process=":background"
        tools:ignore="ExportedReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try with these small changes..

String phoneNumber = intent.getExtras.getString("Intent.EXTRA_PHONE_NUMBER");

             if(phoneNumber.equals("*#588637#")) { 
             //do your stuff
             }

And do not forget to add this line in your Manifest.xml file

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

Also you may find these helpful..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...