Android Study: Jump to the startup management page

Android Study: Jump to the startup management page

Preface

Recently, a project requires the software to start automatically. I thought, why not just register the broadcast statically and listen to the user's boot? I wrote the code according to the idea, but found that I couldn't listen to the boot permission. I was very depressed. After a few days of consulting Baidu and various brain-opening tests, I found that there is something called self-start management. After a simple test, I found that if the user gives the software self-start permission, we only need to statically register the boot broadcast to listen to the user booting, and we can do relevant operations for this situation.

Question extension

But the question arises again, how do we know whether the user has given the software permission to start automatically? After searching for a long time, I couldn't find a solution. However, there are several ways to solve it. Let's take a look at them together.

1. Static registration broadcast, local storage of identification. Mainly monitor the user's power on and off permissions. If the power on permission is monitored, a local identification is saved to prove that the user has given this permission; and when the shutdown is monitored, the identification is set to empty or another identification, indicating that the user cancels the self-start permission. But there is a problem that I have never understood. What should I do if the user sets the self-start at the beginning, but prohibits self-start through other means? It's a bit disgusting. . .

As for broadcasting, some people have proposed monitoring systems for phone calls, text messages, alarms, etc. . . . A series of monitoring, I feel a bit overwhelmed . . .

2. Pop-up window prompts users

When the user logs in, the user is guided to set the auto-start permission for the software.

. . . . . .

There are some other methods, but I personally feel they are not reliable, so I won’t go into detail. Those who are interested can look for them themselves.

After searching for a long time, it was so disgusting that I decided to just give the user a prompt and let the user set the auto-start function through guidance. So, let's take a look at the effect picture first~ Guys, here is the picture~

Since there are many types of mobile phone manufacturers under Android, our first step is to obtain the model of the mobile phone currently used by the user, and then jump to different self-starting interfaces according to the corresponding mobile phone model, so as to guide the user to set the self-starting permission of our software.

Introduce and implement key classes

1. Get the phone model (Build)

Package: android.os.Build

Function (meaning): Extract device hardware and version information from system properties

Static properties:

1.1 BOARD Motherboard: The name of the underlying board, like goldfish.

1.2 BOOTLOADER The system bootloader version number.

1.3 BRAND system customizer: The consumer-visible brand with which the product/hardware will be associated, if any.

1.4 CPU_ABI cpu instruction set: The name of the instruction set (CPU type + ABI convention) of native code.

1.5 CPU_ABI2 cpu instruction set 2: The name of the second instruction set (CPU type + ABI convention) of native code.

1.6 DEVICE Equipment parameters: The name of the industrial design.

1.7 DISPLAY Display parameters: A build ID string meant for displaying to the user

1.8 FINGERPRINT Unique identification code: A string that uniquely identifies this build. Do not attempt to parse this value.

1.9 HARDWARE Hardware name: The name of the hardware (from the kernel command line or /proc).

1.10 HOST

1.11 ID Revision list: Either a changelist number, or a label like M4-rc20.

1.12 MANUFACTURER The manufacturer of the product/hardware. (We only need to focus on this static attribute at present)

1.13 MODEL The end-user-visible name for the end product.

1.14 PRODUCT The name of the overall product.

1.15 RADIO The radio firmware version number. Deprecated after API14. Use getRadioVersion() instead.

1.16 SERIAL A hardware serial number, if available. Alphanumeric only, case-insensitive.

1.17 TAGS: Comma-separated tags describing the build, like unsigned, debug.

1.18 TIME

1.19 TYPE The type of build: The type of build, like user or eng.

1.20 USER

2. Open the Activity or service (ComponentName) in other applications

Package: android.content.ComponentName

The construction method is used as follows:

2.1 Pass the current context and the class name to be jumped;

2.2 Pass a String package name and String class name;

2.3 Pass a Parcel data container.

Methods that need attention: unflattenFromString("pass the address to be jumped, the format is package name/jump Activity Name")

Of course, the above also includes some method properties that have not been introduced. If you are interested, you can take a look~

After the basic understanding, let's start the happy coding journey together~

Create the MobileInfoUtils tool class

The function of this tool class is to obtain the user's mobile phone model and jump to the corresponding management interface through different mobile phone models.

At the same time, we also provide several different ways to achieve jumps. You can check the code carefully~

  1. package cn.hle.skipselfstartmanager.util;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.net.Uri;import android.os.Build;import android.provider.Settings;import android.util.Log;/**
  2. * Mobile Info Utils
  3. * create   by heliquan on March 23, 2017
  4. */ public class MobileInfoUtils { /**
  5. * Get Mobile Type
  6. *
  7. * @return  
  8. */
  9. private static String getMobileType() { return Build.MANUFACTURER;
  10. } /**
  11. * GoTo   Open Self Setting Layout
  12. * Compatible Mainstream Models
  13. *
  14. * @param context
  15. */
  16. public   static void jumpStartInterface(Context context) {
  17. Intent intent = new Intent(); try {
  18. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  19. Log.e( "HLQ_Struggle" , "*********************The current mobile phone model is:" + getMobileType());
  20. ComponentName componentName = null ; if (getMobileType().equals( "Xiaomi" )) { // Redmi Note 4 test passed
  21. componentName = new ComponentName( "com.miui.securitycenter" , "com.miui.permcenter.autostart.AutoStartManagementActivity" );
  22. } else if (getMobileType().equals( "Letv" )) { // LeTV 2 test passed
  23. intent.setAction( "com.letv.android.permissionautoboot" );
  24. } else if (getMobileType().equals( "samsung" )) { // Samsung Note5 test passed
  25. componentName = new ComponentName( "com.samsung.android.sm_cn" , "com.samsung.android.sm.ui.ram.AutoRunActivity" );
  26. } else if (getMobileType().equals( "HUAWEI" )) { // Huawei test passed
  27. componentName = new ComponentName( "com.huawei.systemmanager" , "com.huawei.systemmanager.optimize.process.ProtectActivity" );
  28. } else if (getMobileType().equals( "vivo" )) { // VIVO test passed
  29. componentName = ComponentName.unflattenFromString( "com.iqoo.secure/.safeguard.PurviewTabActivity" );
  30. } else if (getMobileType().equals( "Meizu" )) { //Evil Meizu
  31. // Through testing, I found that Meizu is really disgusting, and that’s enough. In the previous version, I could still view the interface for setting the auto-startup, but after the system update, I couldn’t find it at all. I silently Fucked it in my heart!
  32. // For Meizu, we can only set the auto-start through the built-in mobile manager of Meizu, so I will jump directly to the built-in mobile manager interface of Meizu here. Please see the picture for the specific results
  33. componentName = ComponentName.unflattenFromString( "com.meizu.safe/.permission.PermissionMainActivity" );
  34. } else if (getMobileType().equals( "OPPO" )) { // OPPO R8205 test passed
  35. componentName = ComponentName.unflattenFromString( "com.oppo.safe/.permission.startup.StartupAppListActivity" );
  36. } else if (getMobileType().equals( "ulong" )) { // 360 mobile phone not tested
  37. componentName = new ComponentName( "com.yulong.android.coolsafe" , ".ui.activity.autorun.AutoRunListActivity" );
  38. } else { // The above are just the mainstream models on the market. As you know, it is not easy to get the above equipment together.
  39. // For other devices, we can only adjust the current system app to view the details interface
  40. // Jump to the system settings interface here according to the current version of the user's mobile phone
  41. if (Build.VERSION.SDK_INT >= 9) {
  42. intent.setAction( "android.settings.APPLICATION_DETAILS_SETTINGS" );
  43. intent.setData(Uri.fromParts( "package" , context.getPackageName(), null ));
  44. } else if (Build.VERSION.SDK_INT <= 8) {
  45. intent.setAction(Intent.ACTION_VIEW);
  46. intent.setClassName( "com.android.settings" , "com.android.settings.InstalledAppDetails" );
  47. intent.putExtra( "com.android.settings.ApplicationPkgName" , context.getPackageName());
  48. }
  49. }
  50. intent.setComponent(componentName);
  51. context.startActivity(intent);
  52. } catch (Exception e) {//If an exception is thrown, open the settings page directly
  53. intent = new Intent(Settings.ACTION_SETTINGS);
  54. context.startActivity(intent);
  55. }
  56. }
  57. }

After writing this, you may have questions. How did you find out the specific package name?

Ha, some are donated by Android friends, and some are obtained through adb commands. Let me introduce to you again how to get the jump package name through adb.

Get the jump package name path through adb

Adb provides us with a command that can print out all service information of the current system, followed by a specific service name, which is as follows:

adb shell dumpsys

Here are some commonly used dumpsys-based commands for everyone:

Get device battery information: adb shell dumpsys battery

Get CPU information: adb shell dumpsys cpuinfo

Get memory information: adb shell dumpsys meminfo

To obtain memory information of a specific application, add the package name adb shell dumpsys meminfo PACKAGE_NAME

Get Activity information: adb shell dumpsys activity

Get package information: adb shell dumpsys package

Add -h to get help information

Get information about a package: adb shell dumpsys package PACKAGE_NAME

Get notification information: adb shell dumpsys notification

Get wifi information: adb shell dumpsys wifi

You can get the currently connected wifi name, searched wifi list, wifi strength, etc.

Get power management information: adb shell dumpsys power

You can get whether the screen is locked: mWakefulness=Asleep or mScreenOn=false

Get phone information: adb shell dumpsys telephony.registry

The phone status can be obtained. For example, the mCallState value is 0, indicating standby status, 1 indicates missed call status, and 2 indicates busy status.

mCallForwarding=false #Whether to enable call forwarding

mDataConnectionState=2 #0: No data connection 1: Creating data connection 2: Connected mDataConnectionPossible=true #Is there a data connection mDataConnectionApn= #APN name, etc.

We will use the following command to get the package name of the Activity currently on the top of the stack:

adb shell dumpsys activity top

The literal meaning of the command line is to obtain the information of the Activity currently on the top of the stack (that is, the specific information of the interface we can see).

Then let's take LZ Redmi Note 4 to explain in detail how we can get the package name path of the location interface through the command line.

Use adb to get the location interface package name path details

1. Connect your phone, manually open the system auto-start management interface, then open Android Studio, click Terminal below, enter the above command, and view the information, as shown below:

We see n pieces of information printed out, but the only ones useful to us are those in the red area. Do you understand now?

In the corresponding Activity call, guide the user to set up automatic startup

Here, it is simply written as clicking a button, a pop-up box, and confirming to jump to the startup management interface. Brothers have specific needs and consider implementing them specifically~

  1. public class MainActivity extends Activity { @Override
  2. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
  3. setContentView(R.layout.activity_main);
  4. } public void gotoSelfStartingManager( View   view ){
  5. jumpStartInterface();
  6. } /**
  7. * Jump Start Interface
  8. * Prompt whether to jump to the setting auto-start interface
  9. */
  10. private void jumpStartInterface() { try {
  11. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  12. builder.setMessage(R.string.app_user_auto_start);
  13. builder.setPositiveButton( "Set now" , new DialogInterface.OnClickListener() { @Override
  14. public void onClick(DialogInterface dialog, int which) {
  15. MobileInfoUtils.jumpStartInterface(MainActivity.this);
  16. }
  17. });
  18. builder.setNegativeButton( "Not set yet" , new DialogInterface.OnClickListener() { @Override
  19. public void onClick(DialogInterface dialog, int which) {
  20. dialog.dismiss();
  21. }
  22. });
  23. builder.setCancelable( false );
  24. builder.create ().show();
  25. } catch (Exception e) {
  26. }
  27. }
  28. }

Attached are the results of running jump on Samsung Note5 and Meizu 4. In the tool category, only 360 mobile phone was not tested, and the other tests passed.

Samsung Note5 jumps to the following after clicking:

2. Meizu 4 click and jump to the following:

[[194844]]

Demo address

View Demo source code address: https://github.com/HLQ-Struggle/SkipSelfStartManager

===============This is a magical dividing line===================

Brother w3812127 pointed out that the package location of the auto-startup item of OPPO R9S has changed, and gave the updated coding. Thank you~ I would like to make a supplement here.

("OPPO")) { // OPPO R8205 test passed

componentName =ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");

Intent intentOppo = new Intent();

intentOppo.setClassName("com.oppo.safe/.permission.startup", "StartupAppListActivity");

if (context.getPackageManager().resolveActivity(intentOppo, 0) == null) {

componentName =ComponentName.unflattenFromString("com.coloros.safecenter/.startupapp.StartupAppListActivity");

}

Conclusion

Trying hard is not enough, never giving up is the real thing. I hope everyone can work smoothly, play happily, and play comfortably~ Let's work hard together!

<<:  Who will win the battle of words? ——Front-end and back-end passionate debate

>>:  Do you know how Thread works?

Recommend

How to use fastboot to flash the original image to Android

If your phone has an unlocked bootloader, you can...

6 secrets to achieve explosive growth at low cost

Why should I spread your activity? Why should I b...

Insights and solutions for the automotive industry during the epidemic

At the beginning of the Year of the Rat, a sudden...

How do e-commerce and education industry communities attract new members?

Today I would like to share with you some of my t...

How to promote your brand on TikTok? 5 Tips

According to InfluencerMarketingHub, TikTok has 5...