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~
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~
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:
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?
The China Earthquake Networks Center officially d...
At the 2016 Guangzhou Auto Show, SAIC Roewe relea...
If your phone has an unlocked bootloader, you can...
On January 8, Reuters reported that two people fa...
Why should I spread your activity? Why should I b...
[[136059]] Why this matters Apple's annual Wo...
At the beginning of the Year of the Rat, a sudden...
After the App Store list was updated at 23:00 on ...
Today I would like to share with you some of my t...
More and more businesses are paying attention to ...
According to InfluencerMarketingHub, TikTok has 5...
As the saying goes, water is the source of life. ...
Since the second half of 2016, traditional home f...
The American people have been trying to digest th...
In the golden autumn, there is a "gold among...