我运行在后台的应用程序,当我开始设备电源上的android当我、应用程序、后台、电源

2023-09-05 01:17:22 作者:我们悳傻傻″

可能显示的文件:   如何在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);
    }
}