Steve Miller
Lurker
Hello guyz,
I found a code at stackoverflow... I run this code in an IntenService method onHandleIntent. But nothing happens. The app does not even crash... What I'm trying to do is launch a USSD request and print the result in a Toast. Below is the code I tried
I found a code at stackoverflow... I run this code in an IntenService method onHandleIntent. But nothing happens. The app does not even crash... What I'm trying to do is launch a USSD request and print the result in a Toast. Below is the code I tried
Java:
private void doJob(){
if (ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(mActivityRef.get(),
new String[]{Manifest.permission.CALL_PHONE},
MY_PERMISSION_CALL_PHONE);
}
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
Handler handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
Log.e("ussd",message.toString());
}
};
TelephonyManager.UssdResponseCallback callback = new TelephonyManager.UssdResponseCallback() {
@Override
public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
super.onReceiveUssdResponse(telephonyManager, request, response);
Log.e("ussd","Success with response : " + response);
}
@Override
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
Log.e("ussd","failed with code " + Integer.toString(failureCode));
}
};
try {
Log.e("ussd","trying to send ussd request");
telephonyManager.sendUssdRequest("#106#",
callback,
handler);
}catch (Exception e){
String msg= e.getMessage();
Log.e("DEBUG",e.toString());
e.printStackTrace();
}
}
Last edited: