How can I return back to my Activity from GPS settings window

后端 未结 3 642
悲哀的现实
悲哀的现实 2020-12-10 03:53

I am having a problem in my Activity, which can take the control to the android mobile GPS settings to have user to switch on/off the GPS, But I am unable to retrun back to

相关标签:
3条回答
  • 2020-12-10 04:08
    android:noHistory="true"
    

    removing above from menifest file works for me but data is null inside onActivityResult

    0 讨论(0)
  • 2020-12-10 04:29

    Works for me. Are you sure you have ACCESS_FINE_LOCATION permission set in your manifest? Are you sure startActivityForResult() is being called?

    Also, what is GPS_LOC?

    Here's my code that works:

    public class main extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            findViewById(R.id.button1).setOnClickListener( new OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
                }
            });
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (resultCode == 1) {
               switch (requestCode) {
                  case 1:
                   break;
                }
             }  
         }
    }
    
    0 讨论(0)
  • 2020-12-10 04:30

    On back press from the settings location activity, On Resume is called from the activity that called startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);

    Therefore from there you can check if location has been enabled by

    `if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER )) {//add your logic here }`
    
    0 讨论(0)
提交回复
热议问题