If you think the Android project rfcx-guardian-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.rfcx.guardian.telecom;
/*www.java2s.com*/import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
publicclass CarrierInteraction {
privatestaticfinal String TAG = CarrierInteraction.class.getSimpleName();
privatestaticfinal String NULL_EXC = "Exception thrown, but exception itself is null.";
privatestaticfinal String HASH = Uri.encode("#");
publicvoid takeScreenshot() {
// grab a screenshot of the USSD menu that follows with the balance displayed
try {
Thread.sleep(7000); // pause thread execution to allow time for the menu to load.
ProcessBuilder pb = new ProcessBuilder("su", "-c", "/data/local/fb2png /data/local/img.png");
Process pc = pb.start();
pc.waitFor();
}
catch (Exception e) {
Log.e(TAG, "Failed to take a screenshot");
}
}
publicvoid submitCode(Context context, String code) {
try {
Intent callIntent = new Intent("android.intent.action.CALL",Uri.parse("tel:"+code.replaceAll("#", HASH)));
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(callIntent);
if (code == "#123#") {
takeScreenshot();
}
} catch (Exception e) {
Log.e(TAG,(e!=null) ? (e.getMessage() +" ||| "+ TextUtils.join(" | ", e.getStackTrace())) : NULL_EXC);
}
}
publicvoid closeResponseDialog(String[] commandSequence) {
List<String> cmdSeq = new ArrayList<String>();
for (String command : commandSequence) {
cmdSeq.add("input keyevent "+command.replaceAll("up","19").replaceAll("down","20").replaceAll("right","23").replaceAll("left","21").replaceAll("enter","23"));
}
Log.d(TAG, TextUtils.join(" && ", cmdSeq));
try {
Runtime.getRuntime().exec(new String[] {TextUtils.join(" && ", cmdSeq)});
} catch (IOException e) {
Log.e(TAG,(e!=null) ? (e.getMessage() +" ||| "+ TextUtils.join(" | ", e.getStackTrace())) : NULL_EXC);
}
}
}