Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize App Boot self-start in Android Broadcasting

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today Xiaobian to share with you how to achieve Android radio App boot self-start related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some harvest, let's learn about it together.

I. Summary

In Android, if you want to realize the automatic startup of the app, you need to intercept the broadcast android.permission.RECEIVE_BOOT_COMPLETED, and you need to use the static registration broadcast method (i.e. define the broadcast in the AndroidManifest.xml file);

II. Steps

1. First define broadcast and declaration permissions in the AndroidManifest.xml file;

2. Custom MyReceiver, inherit BroadcastReceiver, code is as follows:

public class MyReceiver extends BroadcastReceiver{ public MyReceiver() { } @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }}

Note: The i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) above is very important, if missing, the program will give an error at startup;

3. Write the MainActivity class as follows:

public class MainActivity extends ActionBarActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toast.makeText(this, "haha, I successfully started! ", Toast.LENGTH_LONG).show(); Log.e("AutoRun","Haha, I successfully started! "); }}

4. Install the app on your phone, and then start the program once (it is said that after Android 4.0, you must start the program once to receive the broadcast of the boot completion, in order to prevent malicious programs)

5. Restart the phone and test whether the app starts automatically. If so, congratulations. If not, look down.

What if there is no automatic startup program after restarting according to all the above steps? What's going on? So first please check if your phone is installed with security software such as 360, if yes, please set the app to [Allow] in the software's self-startup software management (my phone does not have these software installed, but the system settings come with the function of self-startup software management, so I set my app here to [Allow boot]), restart the phone, test whether it is successful. If it still fails, then please check whether your mobile phone is set to install the preferred location of the app is sd card. It is said that if you install it to sd card, the sd card will not be loaded until the mobile phone starts successfully (after sending the broadcast of startup completion), so the app cannot receive the broadcast. If so, try installing the app into internal storage. If you don't know how to set it, set the installation path directly in the AndroidManifest.xml file, android:installLocation="internalOnly". For example:

The above is all the contents of this article "How to realize App boot self-startup of Android radio". Thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report