我的清單中有一個接收器。接收器在Android清單中的兩個動作
<receiver
android:name="com.deviceinventory.StartAppAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartMyServiceAtBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
而且我com.deviceinventory.StartAppAtBootReceiver的onReceive()是
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent startUpIntent = new Intent(context, StartUpActivity.class);
startUpIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startUpIntent);
}
由於StartUpActivity使用互聯網,所以我想,當互聯網連接可用開機後啓動該活動。
目前它在互聯網連接建立之前的某個時間開始。
我不知道如何修改清單中的接收器和BroadCastReceiver
你需要聽'ConnectivityManager.CONNECTIVITY_ACTION'行動廣播... –
然後開始活動之前,你應該檢查網絡的可用性。 –
@SimplePlan我必須在連接可用後開始活動, –