meysam sm
meysam sm

Reputation: 33

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 ?

Upvotes: 3

Views: 1145

Answers (2)

Sanwal Singh
Sanwal Singh

Reputation: 1793

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.

Upvotes: 4

aagalic
aagalic

Reputation: 36

I'm not sure it will be possible to directly open an app via USSD. You may want to use Push Notification. So that when the user dials a USSD code, you send a push notification to the phone for the app to be opened via the notification prompt.

Upvotes: 1

Related Questions