package com.jt.classlibrary;
import java.util.List;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.Settings.Secure;
import android.util.Log;
public class LocationService extends Service implements LocationListener
{
//private LocationAsyncTask asyncTask = null;
//private Timer asyncTimer = null;
private LocationManager lm = null;
//private Location loc = null;
private int iAutoUpdateFrequency = 10000;
private MyBroadcastReceiver broadcast = null;
private ServiceBinder binder = new ServiceBinder();
public class ServiceBinder extends Binder
{
public LocationService getService()
{
return LocationService.this;
}
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
try
{
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
iAutoUpdateFrequency = pref.getInt("AUTO_UPDATE_FREQUENCE", 10000);
}
catch(Exception ex)
{
Log.e("error", "Get SharedPreferences Failed---->" + ex.getMessage());
}
try
{
broadcast = new MyBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConstDef.ACTION_REQUIRE_LOCATION);
//intentFilter.addAction(ConstDef.ACTION_UPMYLOCATION);
registerReceiver(broadcast, intentFilter);
}
catch(Exception ex)
{
Log.e("error", "Register Broadcast Failed---->" + ex.getMessage());
}
try
{
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
/*try
{
if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
if(ConstDef.bOpenGPS)
{
//Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);
}
}
if(!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
if(ConstDef.bOpenNET)
{
//Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.NETWORK_PROVIDER, true);
}
}
}
catch(Exception ex)
{
Log.e("error", "Open GPS or NET Failed---->" + ex.getMessage());
} */
/*List<String> providers = lm.getProviders(false);
for(int i=0;i<providers.size();i++)
{
Log.i("info", providers.get(i));
}*/
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, iAutoUpdateFrequency, 1, this);
}
else if(lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, iAutoUpdateFrequency, 1, this);
}
//asyncTimer = new Timer();
}
catch(Exception ex)
{
Log.e("error", "Set LocationManager Failed---->" + ex.getMessage());
}
Log.i("info", "LocationService Create Success");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
return START_STICKY;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
unregisterReceiver(broadcast);
lm.removeUpdates(this);
Log.i("info", "Service Destroy");
}
@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
Log.i("info", "Service Unbind");
return super.onUnbind(intent);
}
private class MyBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
if(intent.getAction().equals(ConstDef.ACTION_REQUIRE_LOCATION))
{
new LocationAsyncTask().execute((Void[])null);
}
else if(intent.getAction().equals(ConstDef.ACTION_UPMYLOCATION))
{
}
}
}
private class LocationAsyncTask extends AsyncTask<Void, Void, Location>
详细解决方案
LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)老是为false
热度:70 发布时间:2016-04-28 07:21:14.0
相关解决方案
- 怎么取<s:property value="news.CONTENT" escape="false"/>内容前几位
- 为什么Ext.getCmp("panelID").collapsed = false;无效呢
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- Java 中 .setVisible(false);以后是否还在运行
- btn.Enable=false||a>5&&a<100 是如何运算的
- 表单交付给自己,IsPostBack==false
- 后台的textbox控件设置enable=false,怎么使用js设置为true呢
- 怎么修改控件Enabled="false"后的样式
- AutoEventWireup=“false”Page_Load如何执行?
- 为什么小弟我把EnableViewState="false"还是出现了<input type="hidden" name="EVENTTARGET" id="EVENTTARGET" value="" />
- FileUpload.HasFile属性永远为"false"该怎么处理
- EnableViewState,Page=false,TextBox=true,可以么?解决思路
- EnableViewState="False"跟"True"到底有何区别
- EnableViewState="false"禁用不了视图状态是咋回事
- 返回前一頁面的問題:Button1.Attributes.Add("onclick" "history.go(-1);return false;");無效。该怎么解决
- 散分:关于contentEditable="false"的有关问题
- 将Button置为Enabled=False 后再置为true后引发的有关问题
- 在后台,页面加载时小弟我象让所有的checkbox 的visible=false 怎么处理
- 请教下面代码中的EnableViewState="false"是何意?有何用处
- vb.net操作EXCEL,为何设置了excelApp.Visible = False,excel仍然出现
- :document.execCommand('saveas','false','C:\\download.txt');保存文件的文件有关问题,
- HTML控件设立 visible="false" 但还是显示了
- 怎么在网页实现Enabled=False
- 为何 true 输出 1,可是 false 却什么也不输出呢
- 为啥Ext.getCmp("panelID").collapsed = false;无效呢
- django的models.charfield(null=false, max_length=30)的有关问题
- onsubmit 校验表单时利用 ajax 的 return false 无效有关问题
- JQuery中Ajax不能回来return false,已解决
- JavaScript false、0值、null、undefined和空字符串对象
- 新人有关问题,为什么在onclick="return false"中加入函数,它就会跳转,不加就不跳