gps开/关状态改变事件状态、事件、gps

由网友(乄心中的男神)分享简介:我想在我的应用程序中收听 GPS 状态变化,在 android 中是否有任何意图操作,我可以在广播接收器中使用,例如用于网络的 android.net.conn.CONNECTIVITY_CHANGE -状态?I want to listen a GPS state changes in my app, is the...

我想在我的应用程序中收听 GPS 状态变化,在 android 中是否有任何意图操作,我可以在广播接收器中使用,例如用于网络的 android.net.conn.CONNECTIVITY_CHANGE -状态?

I want to listen a GPS state changes in my app, is there in android any intent-action which I can use in a broadCast receiver like an android.net.conn.CONNECTIVITY_CHANGE for network-state?

推荐答案

你可以注册一个BroadcastReceiver来监听Intent Action PROVIDERS_CHANGED_ACTION.或者你可以试试这个片段

You can register a BroadcastReceiver for listening to Intent Action PROVIDERS_CHANGED_ACTION. or you can try this snippet

GpsStatus.Listener gpsListener = new GpsStatus.Listener() {
                    public void onGpsStatusChanged(int event) {
                        if( event == GpsStatus.GPS_EVENT_FIRST_FIX){
                            showMessageDialog("GPS fixed");
                        }
                    }
             };

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.addGpsStatusListener(new android.location.GpsStatus.Listener()
{
    public void onGpsStatusChanged(int event)
    {
        switch(event)
        {
        case GPS_EVENT_STARTED:
            // do your tasks
            break;
        case GPS_EVENT_STOPPED:
            // do your tasks
            break;
        }
    }
});
阅读全文

相关推荐

最新文章