打开gps定位-->发回短信&拦截指令&锁屏&销毁数据&ComponentName
2016-06-10 13:34
459 查看
经纬度 | 地球上的坐标 |
定位原理 | 1.gps定位:基于 人造卫星 精度 准确 受建筑物影响 室内 2.基站定位(辅助) 精度没有gps准确 受基站数量 3.ip定位 静态ip |
goolge定位框架 android.jar |
<!-- FINE精度高 gps -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- COARSE粗糙 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- 使用模拟 -->
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
① 创建定位服务LocationManager
② 创建条件Criteria
③ 创建监听器 LocationListener
借助地图 25.9667,118.5333 格式 纬度,经度
谷歌定位 | 中国 gcj02 火星坐标 国外wgs84 gps坐标 地球坐标 |
|
<span style="font-size:14px;">public class GpsUtils { private static LocationManager lm; /** * 打开定位 * * @param context */ public static void startLocation(Context context) { // ① 创建定位服务LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // ② 创建条件Criteria List<String> pList = lm.getAllProviders();// Provider-->定位器 for (String temp : pList) { Log.i("wzx", temp); MyLocationListener listener = new MyLocationListener(context); // requestLocationUpdates开始定位 // lm.requestLocationUpdates(provider定位器, minTime 时间间隔, minDistance // 最小移动距离,监听器); lm.requestLocationUpdates(temp, 1000, 0, listener); } // 09-11 06:45:20.396: I/wzx(2921): passive // 09-11 06:45:20.396: I/wzx(2921): gps Criteria c = new Criteria(); // Criteria:查询条件 // 查询最适配的定位方式。 // 1.费用 c.setCostAllowed(true); // 2.电量 耗电 c.setPowerRequirement(Criteria.POWER_HIGH);// gps特别耗电 // 3.精度 精确 gpsAccuracy度 c.setAccuracy(Criteria.ACCURACY_FINE); String bestProvider = lm.getBestProvider(c, true); Log.i("wzx", "bestProvider=" + bestProvider); // ③ 创建监听器 LocationListener 比方 :ListView OnItemClickListener // 监听器通常帮助我们获取参数 } public static class MyLocationListener implements LocationListener { private Context context; public MyLocationListener(Context context) { super(); this.context = context; } // 监听获取位置变化 // Location :封装经纬 度坐标的对象 @Override public void onLocationChanged(Location location) { // 移除 lm.removeUpdates(this); Log.i("wzx", "longitude:" + location.getLongitude() + " latitude:" + location.getAltitude()); //短信发回手机 PointDouble newPoint=OffsetUtils.getRightLocation(context, location.getLongitude(), location.getLatitude()); Log.i("wzx", "new longitude:" +newPoint.x + " latitude:" + newPoint.y); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } } }</span>
1.1. 拦截指令
① 创建BroadCastReceiver② Action是类型
③ 权限 短信内容 涉隐私
④ 有序广播 要设置优先级priority
⑤ 解析byte[]-->SmsMessage
<span style="font-size:14px;">public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub // ① 创建BroadCastReceiver // ② Action是类型 // ③ 权限 短信内容 涉隐私 // ④ 有序广播 要设置优先级priority int max = Integer.MAX_VALUE; // ⑤ 解析byte[]-->SmsMessage Log.i("wzx", "onReceive----接收短信" + intent.getAction()); // pdus 协议单元 km Object[] objs = (Object[]) intent.getExtras().get("pdus"); for (Object obj : objs) { byte[] smsBytes = (byte[]) obj; SmsMessage sm = SmsMessage.createFromPdu(smsBytes); String address = sm.getOriginatingAddress();// 获取发送号码 String body = sm.getMessageBody(); if ("$BJ$".equals(body.trim())) { Log.i("wzx", "$BJ$"); abortBroadcast();//销毁广播 } else if ("$GPS$".equals(body.trim())) { Log.i("wzx", "$GPS$"); abortBroadcast();//销毁广播 } else if ("$XH$".equals(body.trim())) { Log.i("wzx", "$XH$"); abortBroadcast();//销毁广播 } else if ("$SP$".equals(body.trim())) { Log.i("wzx", "$SP$"); abortBroadcast();//销毁广播 } } // 解析 } } <uses-permission android:name="android.permission.RECEIVE_SMS" /> <receiver android:name="com.itheima.mobilesafe.receiver.SmsReceiver"> <intent-filter android:priority="2147483647"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver></span>
1.2. 锁屏
<span style="font-size:14px;">public class DeviceUtils { /** * 锁屏 * * @param context */ public static void lockScreen(Context context) { // DevicePolicyManager DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); // dpm重置 密码 dpm.resetPassword("123", 0); //调用锁屏 dpm.lockNow(); }</span>
1.3. 销毁数据
<span style="font-size:14px;">/** * 重置 手机 sd * @param context */ public static void wipe(Context context) { // DevicePolicyManager DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); //重置 dpm.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);//sd格式化 } }</span>
1.4. 超级管理者权限
权限 管理员权限 (按照开发者文档)http://android.xsoftlab.net/guide/topics/admin/device-admin.html
1, 配置权限描述文件 做减法
<device-admin xmlns:android="http://schemas.android.com/apk/res/android" >
<uses-policies>
<!-- 重置 -->
<reset-password />
<!-- 锁屏 -->
<force-lock />
<!-- 重置手机 -->
<wipe-data />
<!-- <limit-password /> -->
<!-- <watch-login /> -->
<!-- <expire-password /> -->
<!-- <encrypted-storage /> -->
<!-- <disable-camera /> -->
</uses-policies>
</device-admin>
2, 配置Reciever的子类 BroadCastreceiver
|---DeviceAdminReceiver 接收授权成功的广播
<!-- 配置 --> <receiver android:name="com.itheima.superadmin.receiver.MobileSafeDeviceAdminReceiver" android:description="@string/desc" android:label="@string/title" android:permission="android.permission.BIND_DEVICE_ADMIN" > <meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin_mobilesafe" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> </intent-filter> </receiver>
3,代码激活/失活
<span style="font-size:14px;">/** * 激活 * * @param context */ public static void active(Context context) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); // ComponentName: 组件属性的对象 举例 <activtity name= <service name <receiver // name ComponentName cn = new ComponentName(context, MobileSafeDeviceAdminReceiver.class); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn); // 打开授权界面 context.startActivity(intent); }</span>
<span style="font-size:14px;">/** * 超级管理账号的应用不能被卸载 * * @param context */ public static void unactive(Context context) { // ComponentName: 组件属性的对象 举例 <activtity name= <service name <receiver // name ComponentName cn = new ComponentName(context, MobileSafeDeviceAdminReceiver.class); // DevicePolicyManager DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); dpm.removeActiveAdmin(cn); }</span>
ComponentName
<span style="font-size:14px;">代表name属性的对象 // ComponentName name=new ComponentName(包名, 类名);<activity name // ComponentName name=new ComponentName(getPackageName(), "com.itheima.mobilesafe.act.AToolsActivity");//<activity name ComponentName name=new ComponentName("com.itheima.mobilesafe", "com.itheima.mobilesafe.act.AToolsActivity");//<activity name // Intent intent = new Intent(this, AToolsActivity.class); Intent intent=new Intent(); intent.setComponent(name); startActivity(intent); $BJ$</span>
销毁数据
1.删除短信
2.删除联系人
3.删除通话记录 邮箱
4.查询手机所有文件的技术 逐个删除
<span style="font-size:14px;">@ViewInject(R.id.admin_active) Button admin_active; @OnClick(R.id.admin_active) public void admin_active(View view) { if(DeviceUtils.isActivity(this)) { DeviceUtils.unactive(this); admin_active.setText("点击激活"); }else { DeviceUtils.active(this); admin_active.setText("点击取消激活"); } } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); if(DeviceUtils.isActivity(this)) { admin_active.setText("点击取消激活"); }else { admin_active.setText("点击激活"); } }</span>
Activity 页面
1.继承
2.重写 (1.布局 分析界面+所有布局+常用控件 设置setContentView2. 写事件)
3.配置
4.打开
快速开发的技巧
style 重用属性 | 1. 控件 重用属性 2. 作于Activity或者 Applicaton 系统 theme |
include 重用布局 | |
selector选择器 | |
使用点九图 | 点九图的制作 sdk/tools |
BroadcastReciever广播接收者 接收系统内的广播 Intent
1.继承
2.重写
3.配置
短信拦截 | 1.action 2.权限 RECEIVE_SMS 3.priroty 4.解析短信 5.销毁 abortBroadcast(); |
Boot拦截 | 1.action 2.权限 RECEIVE_BOOT_COMPELTET |
超级管理员 | 文档完成 |
功能api
MediaPalyer | 播放器 |
LocationManager | android 集成的定位框架 LocationMnaager核心类 封装复杂的定位过程 Criteria 查询 1.费用 2.精度 3.电量 LocationListener 接收定位信息的监听器 权限 ACCESS_FINE_LOCATION ACCESS_CORSE_LOCATION ACESS_MOCK_LOCATION |
DevicePolicyManager | 设备管理 +添加权限 resetPassword lockNow wipeData(); |
相关文章推荐
- 利用wrapper打包java编写的服务注册window服务
- 网络 协议
- 【GOF23设计模式】_装饰模式_IO流底层架构_装饰和桥接模式的区别JAVA240
- Android如何隐藏底部虚拟按键
- 农村土地确权之调查公示 —— ArcGIS中地块分布图标注设置说明[地块分布图制作]
- 【leetcode】96. Unique Binary Search Trees
- CSS3实现炫酷进度条
- PowerDesigner连接数据库附PowerDesigner15.1汉化破解版
- ACM:蓝桥杯:开灯问题
- 求1!+2!+3!+......+n!
- 农村土地确权之调查公示 —— 地块分布图制作说明
- STM32F0xx_PWR低功耗配置详细过程
- 修改js confirm alert 提示框文字的简单实例
- meter度量值,也可用作进度条
- 创建自定义的RouteBase实现(Creating a Custom RouteBase Implementation) |定制路由系统 |
- Broadcast广播机制
- JqueryEasyUi追加自定义工具标签
- 111. Minimum Depth of Binary Tree
- MySQL-5.6.24的配置安装
- iOS视频录制、压缩导出、取帧