Comments (2)
Hi, I have updated the code. Now service will start automatically after booting.
from tracking-location-provider-android.
Great work Martin! I found your source really useful for my app specific use case. However, I didn't find any code to start service automatically after boot is completed.
The code additions below work for me. Can you point out the exact code, if you are handling it differently.
In Manifest.xml add:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
...
<receiver
android:name=".TrackerBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Add a TrackerBroadcastReceiver class as below:
package com.marty.track;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class TrackerBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// This method is called when the BroadcastReceiver is receiving
// an Intent broadcast, which in this case is a power boot completed.
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent start = new Intent(context, MainActivity.class);
start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(start);
}
}
}
from tracking-location-provider-android.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tracking-location-provider-android.