2016-07-15 67 views
3

使用bootcompletedReceiver最近我使用BOOT_COMPLETED 2應用程序(如應用程序,和B的應用程序)優先兩個應用程序在Android

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

一個應用程序是活動和B的應用程序是服務應用

當我的設備引導, 第一個應用程序啓動和B應用程序啓動 所以,顯示B應用程序屏幕。

我想 第一個B應用程序啓動和一個應用程序啓動顯示可能是一個應用程序的屏幕

,我可以給BOOT_COMPLETED優先級是可能的嗎?

最後,我想,當我啓動我的設備,顯示應用屏幕

謝謝!

添加

我嘗試

乙應用(服務)

public class BootCompletedReceiver extends BroadcastReceiver{ 
@Override 
public void onReceive(Context context, Intent intent) { 
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) { 
    Intent i = new Intent("A app package name.BOOT_COMPLETED"); 
    context.sendBroadcast(i); 
    } 
} 
} 


<receiver android:name=".BootCompletedReceiver" 
       android:enabled="true" 
       android:exported="true"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED"/> 
     </intent-filter> 
    </receiver> 

一個應用程序(活動)

public class BootSendReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context,Intent intent) { 
    if(intent.getAction().equals("B app packagename.BOOT_COMPLETED")); 
    Intent i = new Intent (context, MainActivity.class); 
    context.startActivity(i); 

} 
} 




    <receiver android:name=".BootSendReceiver"> 
     <intent-filter> 
      <action android:name="blackeyeonandroid.iosystem.co.kr.simpleserviceexample.BOOT_COMPLETED"/> 
     </intent-filter> 
    </receiver> 

,我嘗試啓動..但顯示乙的應用程序屏幕

回答

0

I認爲你無法控制那個..

取而代之,你可以讓APP1啓動APP2。這樣,只有APP1收到BOOT_COMPLETE消息。然後,APP1負責發送新意圖啓動APP 2:也許

,你可以做如下(注意,APP2沒有收到Android的默認BOOT_COMPLETED消息):

APP1

清單:

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

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

接收機

@Override 
public void onReceive(Context context, Intent intent) { 
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { 
     Intent i = new Intent("com.example.mytestapp.BOOT_COMPLETED"); 
     context.sendBroadcast(i); 
    } 
} 

APP 2

清單:

<receiver android:name=".AppToStartLaterBroadcastReceiver"> 
    <intent-filter> 
     <action android:name="com.example.mytestapp.BOOT_COMPLETED" /> 
    </intent-filter> 
</receiver> 

接收機

@Override 
public void onReceive(Context context, Intent intent) { 
    if (intent.getAction().equals("com.example.mytestapp.BOOT_COMPLETED")) { 
     // Do what you want in secundary APP 
    } 
} 

注意

這是一個建議,你應該調整你的情況。由於我沒有關於你的代碼的更多細節,你可能需要修改它以適應你的情況。但是你可以使用這個想法。

+0

謝謝,我試試這個。請等一下! – chohyunwook

+0

這樣,app1先開始,app2開始? – chohyunwook

+0

我添加了問題如何聲明'LOG','mContext'? – chohyunwook