So, i have gone through internet looking for solution, but didnt find anything that combines what I need.
I need this: if mobile gets restarted, I need to start a service on boot that will every 15 minutes send data to my server. I made code that is working for boot, but don't know how to implement timer. Do I need 2 broadcast receivers and 2 services or?
My broadcast receiver:
public class BrReceiver extends BroadcastReceiver {
final public static String ONE_TIME = "onetime";
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, Service.class);
context.startService(serviceIntent);
}
}
}
and my Service:
public class Service extends IntentService {
private static final String TAG = "DownloadService";
public Service() {
super(Service.class.getName());
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "Service Started!");
}
}
and my AndroidManifest:
<!-- Declaring broadcast receiver for BOOT_COMPLETED event. -->
<receiver android:name=".services.BrReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service
android:name=".services.Service"
android:exported="false" />
This service that is going to be repeated every 15 minutes must not start from the activity, but on boot.