2017-08-24 19 views
1

所以我在清单中添加了BootStarterReceiver接收器, 我在模块文件中添加了OnBootCompletedListener实现。 (这是在模块类btw?正确的做法)如何使用机器人OnBootCompletedListener?

现在我该如何启动应用程序? 我在OnBootCompleted方法中实现了什么?

还有的

cyborg.startActivity() 

,但我不知道如何使用的意图这里我没有任何活动,只控制器。

回答

0

首先,你需要将BootStarterReceiver添加到清单:

<receiver 
    android:name="com.nu.art.cyborg.common.utils.BootStarterReceiver"> 

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

或者只是使BootStarterReceiver如果您使用的是最新版本(0.8.11 +)机器侠版本:

<receiver 
    android:name="com.nu.art.cyborg.common.utils.BootStarterReceiver" 
    android:enabled="true"/> 

您还需要添加相应的权限:

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

完成一个这样的设置,选择你的启动处理模块并实现OnBootCompletedListener,在onBootCompleted方法在那里执行你的代码。

至于盯着这一点的新活动......我不知道你的用户将如何回应,但你可以打电话给cyborg.startActivity(),意图将启动Cyborg的默认ApplicationLauncher和添加FLAG_ACTIVITY_NEW_TASK

public void onBootCompleted() { 
    Intent intent = new Intent(getApplicationContext(), ApplicationLauncher.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    cyborg.startActivity(intent); 
}