Settings.ACTION_LOCATION_SOURCE_SETTINGS vs. Settings.ACTION_SECURITY_SETTINGS
As described in my old post, we can "Start Location setting if GPS disabled" by start activity with intent of "Settings.ACTION_SECURITY_SETTINGS".
Thanks for Brian comments:
It is better to use Settings.ACTION_LOCATION_SOURCE_SETTINGS instead of Settings.ACTION_SECURITY_SETTINGS.
The reason is that some phones (such as HTC Desire) have moved the GPS settings out of the Security page. Using the suggested intent gets the user to the GPS settings wherever they are.
Thanks for Brian comments:
It is better to use Settings.ACTION_LOCATION_SOURCE_SETTINGS instead of Settings.ACTION_SECURITY_SETTINGS.
The reason is that some phones (such as HTC Desire) have moved the GPS settings out of the Security page. Using the suggested intent gets the user to the GPS settings wherever they are.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| package com.AndroidGPS; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.provider.Settings; import android.view.View; import android.widget.Button; import android.widget.TextView; public class AndroidGPS extends Activity { TextView textGpsStatus; Button buttonSetGPS_ACTION_LOCATION_SOURCE_SETTINGS; Button buttonSetGPS_ACTION_SECURITY_SETTINGS; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); textGpsStatus = (TextView)findViewById(R.id.gpsstatus); buttonSetGPS_ACTION_LOCATION_SOURCE_SETTINGS = (Button)findViewById(R.id.setgps_ACTION_LOCATION_SOURCE_SETTINGS); buttonSetGPS_ACTION_LOCATION_SOURCE_SETTINGS.setOnClickListener( new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); }}); buttonSetGPS_ACTION_SECURITY_SETTINGS = (Button)findViewById(R.id.setgps_ACTION_SECURITY_SETTINGS); buttonSetGPS_ACTION_SECURITY_SETTINGS.setOnClickListener( new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS); startActivity(intent); }}); } @Override protected void onResume() { // TODO Auto-generated method stub super .onResume(); displayGpsStatus(); } private void displayGpsStatus(){ ContentResolver contentResolver = getBaseContext().getContentResolver(); boolean gpsStatus = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.GPS_PROVIDER); if (gpsStatus){ textGpsStatus.setText( "GPS: ON" ); } else { textGpsStatus.setText( "GPS: OFF" ); } } }
akm www.cdacians.com |
No comments:
Post a Comment