一:原理分析
  1. 主要sendExtraCommand方法中传递两个参数, 根据如下源码可以知道第一个参数传递delete_aiding_data,第二个参数传递null即可。
    @Override
public boolean sendExtraCommand(String command, Bundle extras) { long identity = Binder.clearCallingIdentity();
boolean result = false; if ("delete_aiding_data".equals(command)) {
result = deleteAidingData(extras);
} else if ("force_time_injection".equals(command)) {
sendMessage(INJECT_NTP_TIME, 0, null);
result = true;
} else if ("force_xtra_injection".equals(command)) {
if (mSupportsXtra) {
xtraDownloadRequest();
result = true;
}
} else {
Log.w(TAG, "sendExtraCommand: unknown command " + command);
} Binder.restoreCallingIdentity(identity);
return result;
}

private boolean deleteAidingData(Bundle extras) {
int flags; if (extras == null) {
flags = GPS_DELETE_ALL;
} else {
flags = 0;
if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS;
if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC;
if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION;
if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME;
if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO;
if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC;
if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH;
if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR;
if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER;
if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA;
if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI;
if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO;
if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL;
} if (flags != 0) {
native_delete_aiding_data(flags);
return true;
} return false;
}

根据flags值GPS_DELETE_ALL清除数据

static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* /* env */,
jobject /* obj */,
jint flags)
{
if (sGpsInterface)
sGpsInterface->delete_aiding_data(flags);
}
    /**
* Specifies that the next call to start will not use the
* information defined in the flags. GPS_DELETE_ALL is passed for
* a cold start.
*/
void (*delete_aiding_data)(GpsAidingData flags);
二:实现方式

java层主要代码如下:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Bundle bundle = null;
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "force_xtra_injection", bundle);
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "force_time_injection", bundle);
//GPS cold start
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", bundle);

所需权限配置如下, 6.0版本可能需要动态申请权限。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

喜欢源码分析系列可参考其他文章:

Android源码分析(一)-----如何快速掌握Android编译文件

Android源码分析(二)-----如何编译修改后的framework资源文件

Android源码分析(三)-----系统框架设计思想

Android源码分析(四)-----Android源码编译及刷机步骤

Android源码分析(五)-----如何从架构师的角度去设计Framework框架

最新文章

  1. 安装Ubuntu的那些事儿(续)
  2. day5 -指针
  3. Spring3中的mvc:interceptors标签配置拦截器
  4. Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
  5. 3.HelloWorld
  6. sql 清空所有数据
  7. linux网络相关
  8. 【转】SqlLite .Net 4.0 System.IO.FileLoadException”类型的未经处理的异常出现在XXX
  9. Top 10 Books For Advanced Level Java Developers
  10. linux中一些常用的目录简要说明
  11. app锁定屏幕方向,某一个界面支持屏幕旋转~
  12. kafka7 探索生产者同步or异步发送消息
  13. Struts2 使用Jquery+ajax 文件上传
  14. css 如何实现图片等比例缩放
  15. ubuntu下配置华为交换机s2016
  16. 谷歌浏览器network请求时间(stalled,DNS Lookup,Waiting)分析以及解决方案
  17. Android开发笔记——ListView模块、缓存及性能
  18. https通讯原理
  19. ES6/ES2015核心内容(上)
  20. HTML— 弹出遮盖层

热门文章

  1. XLA
  2. 毕业一年的大专生程序员工作总结(java后台)
  3. 第一章、Go安装与Goland破解
  4. nginx配置代理时参数说明
  5. vijos2051 SDOI2019 快速查询
  6. 【2019.7.16 NOIP模拟赛 T1】洗牌(shuffle)(找环)
  7. 洛谷P4593 [TJOI2018]教科书般的亵渎
  8. 在程序中修改IP win7 winXP(参考1)
  9. MySQL实战45讲学习笔记:第八讲
  10. [LeetCode] 850. Rectangle Area II 矩形面积之二