2016-07-15 42 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