[Android系统]状态栏上定位状态获取
2015-01-14 22:12
936 查看
1.监听广播:
IntentFilter filter = new IntentFilter();
//监听使能状态监听广播
filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
//监听gps定位广播
filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
context.registerReceiver(this, filter);
2.接收回调:
在onReceive中添加代码:
获取GPS开关状态
final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
boolean visible;
int iconId, textResId;
if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
// GPS is getting fixes
//如果当前为gps定位广播
iconId = com.android.internal.R.drawable.stat_sys_gps_on;
textResId = R.string.gps_notification_found_text;
visible = true;
} else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
// GPS is off
GPS关闭,没有图标显示
visible = false;
iconId = textResId = 0;
} else {
// GPS is on, but not receiving fixes
GPS打开,但是为定位,也就是我们常看到的定位图标闪动
iconId = R.drawable.stat_sys_gps_acquiring_anim;
textResId = R.string.gps_notification_searching_text;
visible = true;
}
IntentFilter filter = new IntentFilter();
//监听使能状态监听广播
filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
//监听gps定位广播
filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
context.registerReceiver(this, filter);
2.接收回调:
在onReceive中添加代码:
获取GPS开关状态
final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
boolean visible;
int iconId, textResId;
if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
// GPS is getting fixes
//如果当前为gps定位广播
iconId = com.android.internal.R.drawable.stat_sys_gps_on;
textResId = R.string.gps_notification_found_text;
visible = true;
} else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
// GPS is off
GPS关闭,没有图标显示
visible = false;
iconId = textResId = 0;
} else {
// GPS is on, but not receiving fixes
GPS打开,但是为定位,也就是我们常看到的定位图标闪动
iconId = R.drawable.stat_sys_gps_acquiring_anim;
textResId = R.string.gps_notification_searching_text;
visible = true;
}
相关文章推荐
- android获取系统wifi状态等
- android获取系统wifi状态等
- Android如何获取系统高度、标题栏和状态栏高度
- Android 获取系统顶部状态栏高度和底部导航栏的高度
- Android 广播BroadcastReceiver静态/动态注册,获取系统电量广播【开机广播】,获取网络状态广播,Timer的使用简介
- Android系统信息获取 之六:网络连接状态信息获取
- Android_获取系统状态栏高度
- Android系统定位获取经纬度
- popupwindow全屏幕显示被状态栏挡住如何解决+Android获取状态栏高度
- Android系统信息获取 之六:网络连接状态信息获取
- Android如何获取系统高度、标题栏和状态栏高度
- popupwindow全屏幕显示被状态栏挡住如何解决+Android获取状态栏高度
- Android获取系统顶部状态栏(StatusBar)与底部工具栏(NavigationBar)的高度
- android 系统获取通话状态的方法
- Android如何获取系统高度、标题栏和状态栏高度
- Android如何获取系统高度、标题栏和状态栏高度
- Android 沉浸式状态栏效果(状态栏与内容完全融合、类似于iphone 7.0系统)
- Android程序:使用系统服务*1.获取网络状态 * 2.打开关闭wifi * 3.获取系统音量 * 4.获取运行程序的包名
- Android获取应用详情页系统通知状态
- Android获取系统高度、标题栏和状态栏高度