教你开启自启动程序! 在电脑的操作系统中都能在电脑开机后自启动一些程序,在Android平台也是可以的,那么我们如何才能做到这样的效果呢。
1、需要BroadcastReceiver
2、使用interfilter中的action:android.intent.action.BOOT_COMPLETED //当启动手机系统启动完成后就启动此Receiver
功能:当手机系统启动完成后,直接启动某个程序或者Activity,这里直接启动某个程序
一下是代码分析:
AndroidManifest.xml文件内容:
Xml代码
# <?xml version="1.0" encoding="utf-8"?>
# <manifest xmlns:android="http://schemas.android.com/apk/res/android"
# package="cc.androidos.sms"
# android:versionCode="1"
# android:versionName="1.0.0">
# <application android:icon="@drawable/icon" android:label="@string/app_name">
# <activity android:name=".StartUp"
# android:label="@string/app_name">
# <intent-filter>
# <action android:name="android.intent.action.MAIN" />
# <category android:name="android.intent.category.LAUNCHER" />
# </intent-filter>
# </activity>
#
# <receiver android:name=".BootReceiver">
# <intent-filter>
# <action android:name="android.intent.action.BOOT_COMPLETED" />
# </intent-filter>
# </receiver>
# <service android:name=".StartService"/>
# </application>
# </manifest>
# <?xml version="1.0" encoding="utf-8"?>
# <manifest xmlns:android="http://schemas.android.com/apk/res/android"
# package="cc.androidos.sms"
# android:versionCode="1"
# android:versionName="1.0.0">
# <application android:icon="@drawable/icon" android:label="@string/app_name">
# <activity android:name=".StartUp"
# android:label="@string/app_name">
# <intent-filter>
# <action android:name="android.intent.action.MAIN" />
# <category android:name="android.intent.category.LAUNCHER" />
# </intent-filter>
# </activity>
#
# <receiver android:name=".BootReceiver">
# <intent-filter>
# <action android:name="android.intent.action.BOOT_COMPLETED" />
# </intent-filter>
# </receiver>
# <service android:name=".StartService"/>
# </application>
# </manifest> 要启动的Activity类:
Java代码
# package cc.androidos.sms;
# import android.app.Activity;
# import android.os.Bundle;
# public class StartUp extends Activity {
# /** Called when the activity is first created. */
# @Override
# public void onCreate(Bundle savedInstanceState) {
# super.onCreate(savedInstanceState);
# setContentView(R.layout.main);
# }
# }
# package cc.androidos.sms;
# import android.app.Activity;
# import android.os.Bundle;
# public class StartUp extends Activity {
# /** Called when the activity is first created. */
# @Override
# public void onCreate(Bundle savedInstanceState) {
# super.onCreate(savedInstanceState);
# setContentView(R.layout.main);
# }
# } Receiver类:系统启动后接受信息的类
Java代码
# package cc.androidos.sms;
# import android.app.Activity;
# import android.app.PendingIntent;
# import android.content.BroadcastReceiver;
# import android.content.Context;
# import android.content.Intent;
# import android.net.Uri;
# import android.util.Log;
# public class BootReceiver extends BroadcastReceiver
# {
# @Override
# public void onReceive( Context context, Intent intent )
# {
# if(intent.getAction().equals( Intent.ACTION_BOOT_COMPLETED )){
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Intent i = new Intent(context,StartUp.class);
# i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
# //使用Receiver直接启动Activity时候需要加入此flag,否则系统会出现异常
# context.startActivity( i );
#
# }
# }
# }
# package cc.androidos.sms;
# import android.app.Activity;
# import android.app.PendingIntent;
# import android.content.BroadcastReceiver;
# import android.content.Context;
# import android.content.Intent;
# import android.net.Uri;
# import android.util.Log;
# public class BootReceiver extends BroadcastReceiver
# {
# @Override
# public void onReceive( Context context, Intent intent )
# {
# if(intent.getAction().equals( Intent.ACTION_BOOT_COMPLETED )){
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Log.d( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", "boot start................" );
# Intent i = new Intent(context,StartUp.class);
# i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
# //使用Receiver直接启动Activity时候需要加入此flag,否则系统会出现异常
# context.startActivity( i );
#
# }
# }
# } 第一个运行完成后,关闭手机模拟器或者手机,然后启动手机操作系统,启动完成后StartUp Activity会自动运行。
分享到:
相关推荐
// 在这里启动你的应用程序或服务 Intent appIntent = new Intent(context, YourActivity.class); appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(appIntent); } } } ``` 2. **...
在Windows 10操作系统中,实现exe程序随系统开机自动启动可以通过多种方式完成。本教程将介绍如何通过编写批处理脚本并利用本地组策略编辑器来实现开机启动exe程序的配置。这种方法适用于通过使用sc create命令创建...
标题中的“开机自启动并全屏浏览指定网址的安卓APP开发”涉及到的是Android应用程序的开发技术,特别是关于启动服务(Boot Receiver)和Webview的使用。在这个项目中,开发者将创建一个Android应用,该应用在设备...
本教程将详细介绍如何使用RaiDrive来挂载阿里云盘到本地,并设置开机自启动,从而实现无缝的云存储体验。 首先,你需要确保已安装RaiDrive。如果你还没有安装,可以从官方网站下载最新版本的RaiDrive安装程序,按照...
在Android系统中,APP自启动是指应用程序在手机开机或者用户解锁屏幕后自动运行的功能。这在某些场景下是必要的,比如天气更新、消息推送服务等。本教程将详细讲解如何在Android项目中实现一个单独的APP自启动模块。...
通过打开并分析这些文件,你可以更深入地理解VB中如何实现隐藏运行和开机自启动的细节。如果你需要进一步学习VB编程或了解更多相关知识,建议参考VB的官方文档或在线教程,以便系统地掌握这门语言。
"开机启动程序"是指能够在计算机启动时自动运行的程序。在Windows操作系统中,可以通过修改注册表来实现开机启动。本文将深入探讨如何使用C#编写开机启动程序以及涉及的相关知识点。 首先,我们需要了解注册表是...
本教程将深入讲解FANUC机器人如何通过自动运行方式启动程序,涉及的主要内容包括程序启动类型、自动运行的启动条件以及RSR(Robot Service Request)和PNS(Program Number Select)两种启动方式的定义、特点、命名...
在本文中,我们将深入探讨如何使用 RaiDrive 软件将阿里云盘挂载到本地计算机,并设置为开机自启动。RaiDrive 是一个高效、便捷的网络驱动器工具,它允许用户将各种云存储服务作为本地磁盘访问,极大地提高了工作...
### Tomcat自启动详解:如何实现解压缩版Tomcat服务自动启动 在现代Web开发环境中,Apache Tomcat作为一款广泛使用的开源Servlet容器,为Java Web应用程序提供了强大的支持。然而,默认情况下,Tomcat并不会随着...
需要注意得是有的手机安全软件与设置需要设置自启动权限才能看到效果有些机器由于系统限制也可能看不到效果。本项目自启动类名为unity默认com.unity3d.player.UnityPlayerActivity类, 可自行修改编译arr文件给unity...
如果你是开发者,这将帮助你理解如何在实际项目中应用这一技术,例如创建自启动的服务或应用程序。 需要注意的是,为了保持系统的稳定性和安全性,应谨慎处理开机启动项。过多的开机启动程序会延长启动时间,并可能...
总之,通过上述步骤,你可以创建一个能在后台运行、自启动且不显示图标的服务。然而,这样的功能应当谨慎使用,遵循最佳实践和用户隐私政策,以避免被系统限制或引起用户不满。在实际开发过程中,还应考虑电量和性能...
"软件自动运行"这一概念涉及到操作系统启动过程中的自启动机制。在Windows系统中,可以通过注册表、启动文件夹等方式设置程序在系统启动时自动运行。这种特性在需要后台服务、定时任务或者用户登录后自动执行某项...
#### 实现VxWorks自启动程序的目标 本教程旨在详细介绍如何在VxWorks启动过程中自动运行特定的用户程序。我们将通过一个具体的示例来展示如何实现这一点:在VxWorks启动完成后自动启动用户定义的`demo()`和`welcome...
在Windows操作系统中,开机自动运行程序是指在系统启动时能够自动执行的程序。VB6.0(Visual Basic 6.0)是微软公司推出的一种面向对象的编程...继续深入学习VB6.0和Windows API,你将能够实现更复杂的自启动管理功能。
在Android系统中,后台保持运行并实现开机自动启动是许多应用程序的需求,比如闹钟应用、消息推送服务等。本教程将介绍如何通过源码实现这一功能。首先,我们需要理解Android系统的运行机制,尤其是关于服务...
在这里,`path\to\program.exe`是你要打开的EXE文件的完整路径,`WindowStyle`参数则可以控制新启动程序的窗口样式,如隐藏、最大化、最小化等。例如,如果你想要打开C盘根目录下的`example.exe`程序,并且让它以...
本教程将详细介绍如何使用C#编写小程序来实现程序开机自启动的功能。开机自启动是指程序能够随计算机启动时自动运行,这对于那些需要后台常驻或者定时执行任务的应用来说尤其重要。 首先,我们需要理解的是开机自...
### 树莓派基础配置与Java程序自启动详解 #### 一、树莓派系统安装与基本配置 **树莓派系统安装步骤:** 1. **格式化内存卡:** 使用SD Formatter等工具对SD卡进行格式化处理,确保SD卡处于良好的状态,避免因卡顿...