我运行在后台的应用程序,当我开始设备电源上的android [英] Run my application in background when i start device power on in android

查看:113
本文介绍了我运行在后台的应用程序,当我开始设备电源上的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:
  如何在Android中创建启动应用程序?
  如何自动启动的Andr​​oid应用程序?

Possible Duplicates:
how to create startup application in android?
How to Autostart an Android Application?

您好,

我想在我的应用程序之一,当我要开始我的意思是电源在我的谷歌Android G1我的应用程序将自动启动,但我无法理解如何 我这样做,请帮助......

I am trying in one of my application when i am going to start i mean power on my google android g1 my application automatically will start but i am unable to understand how can i do that please help......

推荐答案

下面是什么,我认为你试图做一个基本的例子。你需要做的几件事情。首先,授予应用程序的权限来侦听启动完成的信号。在你的Andr​​oidManifest.xml中,在清单中添加该行:

Here's a basic example of what I think you're trying to do. You'll need to do a few things. First, grant your application permission to listen for a "Boot completed" signal. In your AndroidManifest.xml, add this line in the manifest section:

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

在你的应用程序部分,添加并为此目的指定广播接收器:

Under your application section, add and specify a broadcast receiver for this intent:

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

您还需要一个广播接收器将响应这个意图,并在开机启动的服务。在你的项目中创建MyBroadcastReceiver.java:

You also need a broadcast receiver which will respond to this intent and start your service at boot. Create MyBroadcastReceiver.java in your project:

package com.mypackage.myapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context aContext, Intent aIntent) {

        // This is where you start your service
        startService(new Intent(aContext, MyService.class);
    }
}

这篇关于我运行在后台的应用程序,当我开始设备电源上的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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