如何在启动android mobile时打开我的android应用程序? [英] How to open my android app at a start up of android mobile?

查看:86
本文介绍了如何在启动android mobile时打开我的android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在启动时启动应用程序?

Possible Duplicate:
How to Start an Application on Startup?

我是android的新手,我有我的android应用程序.我只想在启动Android手机时打开我的应用程序.请告诉我该怎么做?我正在将Eclipse与android sdk 2.3.3一起使用

I am new to android and I have my android app. I just want to open my app at start up of my android mobile. Plz tell me How to do this? I am using Eclipse with android sdk 2.3.3

推荐答案

如果要务实地做

<receiver android:name=".MyServiceManager"
        android:enabled="true" >

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

然后只需将此代码添加到清单文件的应用程序标记中,并将使用权限添加到清单文件中.

then just add this code into application tag of your manifest file and add usages permission into manifest file.

然后

public class MyServiceManager extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

        if(action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED"))
        {
            Intent myIntent=new Intent(context,package.YourActivity.class);
            myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(myIntent);
        }
}   

将此类添加到您的项目中. 请检查包名称和类名称,并进行相应的更改. 如果您仍然有问题,请写信给我.

add this class into your project. Please check package name and class name and change it accordingly. If you still have problem then write me.

这篇关于如何在启动android mobile时打开我的android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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