how to start my application when ever mobile restart or turn on
Asked Answered
C

3

1

How do i set my application as startup application, so when ever mobile restarts or turned ON, my application starts.

  <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.installedapps22"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

 <application android:icon="@drawable/cherry_icon" android:label="@string/app_name">
    <activity android:name=".MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".ListInstalledApps" > </activity> 


<activity android:name=".TabsLayoutActivity" />
</application>
   </manifest>

EDIT Here is my updated code and it is still not working:

Manifest:

 <?xml version="1.0" encoding="utf-8"?>

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.installedapps22"
android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 <application android:icon="@drawable/cherry_icon" android:label="@string/app_name">
    <activity android:name=".MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
  <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
 </receiver>
  <activity android:name=".ListInstalledApps" > </activity> 


  <activity android:name=".TabsLayoutActivity" />
  </application>
 </manifest>

BroadcastReciever:

 package com.example.installedapps22; 
 public class BootUpReciever extends BroadcastReceiver
 {

    @Override
    public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, MainActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
 }
Connivent answered 18/6, 2013 at 11:54 Comment(0)
A
4

This is to set the app as the startup application in your device Create a Class extends BroadCast Reciever

public class BootUpReciever extends BroadcastReceiver
{

@Override
public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, ServerPreferenceActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
}
}

Add permissions to manifest file to access bootup receiver

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

Register your receiver which extended the Broadcast receiver in manifest.xml

<receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
    <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>
Auricular answered 18/6, 2013 at 11:56 Comment(6)
add it inside the application tagAuricular
here is what you must replace with, MainActivity.classAuricular
i want to start my applictaion when ever system restrt or UnlockConnivent
you cannot start application on unlock or something, it will start when ever the mobile or tablet will start.Auricular
where have you put the receiver class ?Auricular
#17169324 see tis my postConnivent
S
2

first use permission in manifiest

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

and declare boot receiver in manifiest

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

user receiver to start your mainactivity

public class BootReciever extends BroadcastReceiver
{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Intent myIntent = new Intent(context, MainActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(myIntent);
}

}
Sourdine answered 18/6, 2013 at 11:57 Comment(3)
have u give complete path of package inside manifiest of bootreceiverSourdine
give me any example application pleaseConnivent
you have to put complete path or boot receiver receiver android:name="com.example.BootReciever where you have made boot receiver class with in packageSourdine
P
0

For your edited code try replacing the following:

android:name="com.app.reciever.BootUpReciever

with:

android:name="com.example.installedapps22.BootUpReciever
Pahang answered 18/6, 2013 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.