James Hoffman
James Hoffman

Reputation: 153

How to create an android app that is set to default when the device is turned on

I want to create an application in android , which after installation I need to set as default when ever the device is turned on .

I have tried the following

created a service , created a reciever to recieve boot completion event

It is not working actually.If I remove the launcher for MainActivity the it will show error saying

No Launcher activity found!
The launch will only sync the application package on the device!

my manifest file

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

         <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="sensorLandscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name=".MyService"
            android:label="My Service" >
            <intent-filter>
                <action android:name="com.example.splash_test.MyService" />
            </intent-filter>
        </service>

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


            </intent-filter>
        </receiver>

         <activity
            android:name="com.example.splash_test.Screen1"
            android:label="@string/app_name"
            android:screenOrientation="sensorLandscape" >
            </activity>
    </application>

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Intent serviceIntent = new Intent(context, MyService.class);
            context.startService(serviceIntent);
        }
    }

}

MyService.java

public class MyService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub

        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

            Intent i = new Intent(this, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            this.startActivity(i);
        }
        return null;
    }

}

Upvotes: 0

Views: 149

Answers (1)

Vishnu
Vishnu

Reputation: 711

You have to follow below steps for achieve this task:-

  1. Make a service in your app(Run all time).
  2. check your app is running or not in service.(Through package name)
  3. if running then good other wise run with the help of service.

Try it.... its working fine in my app. :)

Upvotes: 2

Related Questions