我添加我的後臺服務運行完美,但我的手機關閉,然後打開然後我的reciver類在獲取操作android.intent.action.BOOT_COMPLETED.but服務不start.my代碼請幫助我!BOOT_COMPLETED之後爲什麼不啓動服務?
public class ReceiverCall extends BroadcastReceiver {
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
static final String ACTION1 = "android.intent.action.QUICKBOOT_POWERON";
@Override
public void onReceive(Context context, Intent intent) {
Log.v("log_tag", "Action :: "+intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
/* Setting the alarm here */
Intent alarmIntent = new Intent(context, MyAlarmService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), + (1000 * 60 * 2), pendingIntent);
Log.v("log_tag", "REPEAT");
}
}
而且我還在顯示中添加權限。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.employeemanager.app.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity
android:name="***8"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="***.MyAlarmService"
android:enabled="true" >
</service>
<receiver android:name="***.ReceiverCall"
android:enabled="true" >
<intent-filter>
<action android:name="***" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
<category android:name="android.intent.category.LAUNCHER" >
</category>
</intent-filter>
</receiver>
</application>
您的應用程序在SD卡上嗎?另外,當你把你的接收器和服務放在你的清單上時,試着把整個軟件包寫成:com.your.package.ReceiverCall並讓我知道它是否可用 –
Skizo我也添加了完整的軟件包名稱,但沒有任何工作。 – crickpatel0024
查看我的回答請 –