Android 从广播接收器启动服务以查找gps位置
我是android新手,我正在尝试在收到短信时访问gps位置。 我是这样给服务打电话的:Android 从广播接收器启动服务以查找gps位置,android,android-intent,Android,Android Intent,我是android新手,我正在尝试在收到短信时访问gps位置。 我是这样给服务打电话的: Intent findGPS = new Intent(context, MyService.class); context.startService(findGPS); 我试图在服务类中打印吐司,以便知道它是否已开始,但它不打印吐司。有人能建议我如何为位置访问编写服务类吗 公共类MyService扩展服务{ public void onCreate() }当您收到广播时,服务将自动调用 publi
Intent findGPS = new Intent(context, MyService.class);
context.startService(findGPS);
我试图在服务类中打印吐司,以便知道它是否已开始,但它不打印吐司。有人能建议我如何为位置访问编写服务类吗
公共类MyService扩展服务{
public void onCreate()
}当您收到广播时,服务将自动调用
public class BReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
// call your service here
startService(new Intent(getapplicationcontext(),ImageDownloader .class));
} catch (Exception e) {
e.printStackTrace();
}
}
}
//创建一个java类并使用intent service对其进行扩展,因为它具有停止自我功能,因为服务在后台运行时会耗尽电池,这就是为什么我建议您使用intent service,在完成任务后,它将自动停止
服务类别:
它是一种什么样的服务?你能发布相关代码吗..我的SMSBroadcastReceiver类调用我试图获取gps位置的服务类。请粘贴服务代码..或者在服务的onCreate方法中打印日志。并确保在清单中使用完全限定的类名声明服务,例如:com.example.service
public class BReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
// call your service here
startService(new Intent(getapplicationcontext(),ImageDownloader .class));
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class ImageDownloader extends IntentService {
public ImageDownloader() {
super("DownLoadImages");
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void onHandleIntent(Intent intent) {
// do your stuff here
}
}