Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

android - how to start my application when ever mobile restart or turn on

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);
    }
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...