使用 Little Fluffy 位置 1º:
在清单中:
<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º 创建类以扩展应用程序
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º 创建广播接收器
public class Broadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final LocationInfo locationInfo = (LocationInfo) intent.getSerializableExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO);
}
}
并使用:
在您的活动中:
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;
}
}
需要更多?
请参考这里
为我工作!