Android 将感测数据从位置传感器发送到服务器的服务

Android 将感测数据从位置传感器发送到服务器的服务,android,android-service,android-sensors,Android,Android Service,Android Sensors,我是android新手。我需要一个服务(在一个单独的线程中),它定期将感测到的数据从位置传感器发送到服务器。有人能举例说明吗。我的意思是服务的一部分,如何在一个单独的线程中实现它,在这个线程中放置代码以向服务器发送数据。我已经实现了从传感器获取数据的代码 提前谢谢 您必须通过使用startForeground 阅读本文: 读这篇文章: 很多方法都被贬低了,我无法尝试回答! final static int myID = 1234; //The intent to launch when th

我是android新手。我需要一个服务(在一个单独的线程中),它定期将感测到的数据从位置传感器发送到服务器。有人能举例说明吗。我的意思是服务的一部分,如何在一个单独的线程中实现它,在这个线程中放置代码以向服务器发送数据。我已经实现了从传感器获取数据的代码


提前谢谢

您必须通过使用
startForeground

阅读本文:

读这篇文章:


很多方法都被贬低了,我无法尝试回答!
 final static int myID = 1234;

//The intent to launch when the user clicks the expanded notification
Intent intent = new Intent(this, SomeActivityToLaunch.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

//This constructor is deprecated. Use Notification.Builder instead
Notification notice = new Notification(R.drawable.icon_image, "Ticker text", System.currentTimeMillis());

//This method is deprecated. Use Notification.Builder instead.
notice.setLatestEventInfo(this, "Title text", "Content text", pendIntent);

notice.flags |= Notification.FLAG_NO_CLEAR;
startForeground(myID, notice);