Android. Launch app from Dialer

丶灬走出姿态 提交于 2019-11-29 02:24:17
ridoy

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..

Is the receiver getting the broadcast at all? If not, maybe you forgot to include the PROCESS_OUTGOING_CALLS permission.

According to ridoy's 2nd link,

http://tikuflower.blogspot.com/2011/12/android.html

It should be

String phoneNumber = intent.getStringExtra("android.intent.extra.PHONE_NUMBER");

rather than

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

That change works for me at least...

Try This,

Add to this in manifest, here host is 12456, so your secret code is *#*#123456#*#* (dial-in dialped)

<receiver android:name=".Dialer"> //here is your broadcast receiver class
        <intent-filter>
            <action android:name="android.provider.Telephony.SECRET_CODE" />
            <data android:scheme="android_secret_code"
                  android:host="123456"
            />
        </intent-filter>
    </receiver>

here is your Broadcast Receiver class :

 class Dialer : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
         // Declare Here your launcher activity in Intent
        var  i : Intent = Intent(context, MainActivity::class.java)  
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context!!.startActivity(i);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!