2013-06-18 72 views
-1

我如何設置我的應用程序作爲啓動應用程序,所以當移動設備重新啓動或打開時,我的應用程序啓動。如何啓動我的應用程序,當有移動重啓或打開

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

編輯這是我更新的代碼,它仍然沒有工作:

清單:

<?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); 
    } 
} 

回答

4

這是設置應用程序作爲設備中的啓動應用程序創建一個類擴展廣播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); 
} 
} 

添加權限清單文件訪問在啓動接收器

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

填寫您的接收器中的manifest.xml延長Broadcast receiver

<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> 
+0

我應該在哪裏接受mannifeist?裏面的活動標籤? –

+0

將它添加到應用程序標記 –

+0

ServerPreferenceActivity.class)是我的第一個活動類????? –

1

首次使用許可,manifiest

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

,並宣佈啓動接收機manifiest

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

用戶接收到啓動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); 
} 

} 
+0

沒有不工作 –

+0

你有沒有給包內完整路徑bootreceiver – abhi

+0

給我任何示例應用程序請 –

0

爲您編輯的代碼嘗試更換如下:

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

有:

android:name="com.example.installedapps22.BootUpReciever 
+0

確定引導接收器類好w8我會檢查 –

相關問題