androidussd

Is there any way to open an app with ussd?


Is it possible to when a user uses a USSD code in his phone after he pushes the call button my app going to open? like you use this code *123*2# and the app open and shows you type '2'!

I have never seen an app like this but it's worth the try

Thanks in advance.

or when a user use ussd a link on web open ? like this *123*1*2# after call a link like site.com/abc.php open ?


Solution

  • You have to create Broadcast Receiver to get what you want.

    Format of number *#*#xxxx#*#*, like- *#*#125#*#*.

    Now Create a Receiver

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    
    public class OpenApp extends BroadcastReceiver {
    
    @Override
     public void onReceive(Context context, Intent intent) {
     String val = intent.getData().getHost();
     Intent i = new Intent(context, MainActivity.class);
     i.putExtra("data", val);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     context.startActivity(i);
     }
    }
    

    Now register receiver in AndroidManifest:

    <receiver android:name=".OpenApp">
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE" />
        <data android:scheme="android_secret_code" android:host="125"/>
    </intent-filter>
    

    That's all.