Using a small fluffy location of 1ΒΊ:
in manifest:
<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_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-feature android:name="android.hardware.location" android:required="true" /> <uses-feature android:name="android.hardware.location.gps" android:required="false" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <Application...> <service android:name="com.littlefluffytoys.littlefluffylocationlibrary.LocationBroadcastService" /> <receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.StartupBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.PassiveLocationChangedReceiver" android:exported="true" />
2ΒΊ Create a class to extend the application
public class YourApplication extends Application { public void onCreate(){ super.onCreate(); LocationLibrary.showDebugOutput(true); LocationLibrary.initialiseLibrary(getBaseContext(), 0, 2 * 60 * 1000, "com.yourpackage.broadcastpackage"); } public static Context getAppContext() { return ApplicationVexPromoter.context; } }
3ΒΊ Creating a Broadcast Receiver
public class Broadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final LocationInfo locationInfo = (LocationInfo) intent.getSerializableExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO); } }
And Usage:
in your activity:
public class YourActivity extends Activity { LocationInfo info; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.id.yourview); info = new LocationInfo(getBaseContext()); double latitude = info.lastLat; double longitude = info.lastLong; } }
Need more? Refer to this question
It works for me!
source share