How do I know if users have really turned GPS/Network on after directing them to the settings page?

StackOverflow https://stackoverflow.com/questions/15234678

質問

I am building a location finding application which requires GPS or Network operations. I want to be able to direct users to the GPS or the Wireless settings to force them to turn it on if they don't have it on. My question is, how do I check if they really have turned the providers on after the settings page?

Below is the usual code to direct users to the settings. What would I do after that?

LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabled = service
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    } 
役に立ちましたか?

解決

What would I do after that?

Nothing.

You are presumably (hopefully?) checking whether you can use GPS in onResume() of your activity. That logic will be invoked again when control returns to your activity from the Settings activity. Hence, you will go through the same logic again.

他のヒント

Use startActivityForResult instead of startActivity. Then in onActivityResult check isProviderEnabled again. This should work, unless idProviderEnabled won't return true until you have GPS synch, which I don't think is the case. Same thing should work for wifi.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top