Android的自动启动应用程序 [英] Android autostart application

查看:138
本文介绍了Android的自动启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能自动启动,在设备启动(与启用/禁用这一功能的可能性),我的应用程序的服务?我在AndroidManifest包括哪些权限?

How can I autostart my application's service at device boot (with the possibility of enabling/disabling this feature)? What permissions do I have to include in AndroidManifest?

感谢

推荐答案

此权限是使用

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

在你的&lt;应用&GT;元(一定要使用完全合格的[或相对]类的名称为您的BroadcastReceiver):

In your <application> element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver):

<receiver android:name="com.example.MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>

在MyBroadcastReceiver.java:

In MyBroadcastReceiver.java:

package com.example;

public class MyBroadcastreceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, MyService.class);
        context.startService(startServiceIntent);
    }
}





有关更多帮助:: HTTP://www.androidcompetencycenter。 COM / 2009/06 /启动服务的启动/                   http://blog.gregfiumara.com/archives/82                  的http://androidgps.blogspot.com/2008/09/starting-android-service-at-boot-time.html

for more help :: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ http://blog.gregfiumara.com/archives/82 http://androidgps.blogspot.com/2008/09/starting-android-service-at-boot-time.html

这篇关于Android的自动启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆