Programmatically enter secret code like *#*#4636#*#* on Android
Is it also possible to open this stuff programmatically?
Yes:
Intent in = new Intent(Intent.ACTION_MAIN);
in.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(in);
You just need to watch logcat output to learn what this magic combination actually opens:
I/ActivityManager(31362): START {act=android.intent.action.MAIN
flg=0x10000000 cmp=com.android.settings/.TestingSettings} from pid
4257
Android development: hook shortcut on keyboard when phone app activity is focused
Ok I finally got this working on the HTC device. The fact is Samsung phones doesn't seems to react to secret codes ...
I simply have this manifest :
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MenuBrowser"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".ShortcodeService"
android:exported="false">
</service>
<receiver
android:name=".ShortcodeReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="1992" />
</intent-filter>
</receiver>
</application>
My service is simply checking for the right permissions for Android M (6.0), because the security has changed a bit. We now have to declare permission on-the-fly during the application runtime, and not at installation.
My activity:
public class MenuBrowser extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("USSDBrowser", "Start app");
//if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.PROCESS_OUTGOING_CALLS}, 10);
Intent serviceIntent = new Intent(this.getApplicationContext(), ShortcodeService.class);
startService(serviceIntent);
//setContentView(R.layout.activity_menu_browser);
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_menu_browser, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And my receiver is like this :
public class ShortcodeReceiver extends BroadcastReceiver {
private static String defaultCode = "1992";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("USSDBrowser", "Intent received");
if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
String code = intent.getDataString();
if(code.equals("android_secret_code://" + defaultCode)) {
Log.d("USSDBrowser", "Code received !!! ");
}
//Intent in = new Intent(context, MenuBrowser.class);
//context.startActivity(in);
Toast.makeText(context, "You typed a shortcode, hype !", Toast.LENGTH_LONG).show();
}
}
}
But now I tested that and it's working for HTC One S (Android 4.1.1) and Aquaris E4 (Android 4.4.2).
The phones tested that does not capture secret code intents are : Samsung Galaxy S4 and Galaxy S6 (Android 6.0).
Related Topics
How to Change the Color of the Tabs Indicator Text in Android
How to Get Free and Total Size of Each Storagevolume
Httpentity Is Deprecated on Android Now, What's the Alternative
How How to Do Ussd Requests on Android
How to Rename a File on Sdcard with Android Application
How to Create Parallelogram Shape Background
Android: Xml Layout for a Listview with Different Items
Picasso Illegalargumentexception Target Must Not Be Null
How to Make a Edittext Box in a Dialog
Convert Xml to JSON Object in Android
How to Change Color of Listview Items on Focus and on Click
How to Execute a Method by Clicking a Notification
Android Make Animated Video from List of Images
How to Set Up Screen Lock with a Password Programmatically
Fragment-Fragment Communication in Android