my App has a camera photo backup service. When user turned on the service, it will automatically backup sd-card photos to remote server. But when user shut down android OS and boot again, the backup service failed to start again.
I read many articles online, I did exactly the same as they described, but turned out to be wrong. Maybe some experts here can help me. see the code below.
In android manifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:name="com.seafile.seadroid2.SeadroidApplication"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<receiver android:name=".OSBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
OSBootReceiver class
public class OSBootReceiver extends BroadcastReceiver {
private static final String DEBUG_TAG = "OSBootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(DEBUG_TAG, "boot to notic receiver");
Intent cameraUploadIntent = new Intent(context,
CameraUploadService.class);
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(context);
boolean isUploadStart = settings.getBoolean(
BrowserActivity.CAMERA_UPLOAD_SWITCH_KEY, false);
if (!isUploadStart) {
return;
}
Log.d(DEBUG_TAG, "boot to start service");
context.startService(cameraUploadIntent);
}
}
I tried to reboot os many times, but didnt fond any log printed! any advice will be appreciated.
0 comments:
Post a Comment