How to open my android app at a start up of androi

2019-07-17 01:47发布

Possible Duplicate:
How to Start an Application on Startup?

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

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-17 02:14

If you want to do it pragmatically

<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.

Then

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.

查看更多
太酷不给撩
3楼-- · 2019-07-17 02:21

Give permission in manifest.....

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

In your receiver give this to intent filter...

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

Try this code in receiver class.....

 @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            Intent serviceIntent = new Intent("*package name*.*Receivername*");
            context.startService(serviceIntent);
        }
    }

For more update about android visit this website.

查看更多
登录 后发表回答