List of usage examples for android.location LocationManager PROVIDERS_CHANGED_ACTION
String PROVIDERS_CHANGED_ACTION
To view the source code for android.location LocationManager PROVIDERS_CHANGED_ACTION.
Click Source Link
From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fixtures_layout, container, false); ButterKnife.inject(this, view); buildGoogleApiClient();//from ww w. j a v a2s .c o m //Registering events to detect radio changes final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { updateBluetoothStatusDisplay(); } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { updateWifiStatusDisplay(); } else if (action.equals(LocationManager.PROVIDERS_CHANGED_ACTION)) { updateGPSStatusDisplay(); } else if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) { updateNFCStatusDisplay(); } } }; IntentFilter filter = new IntentFilter(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); } filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); updateWifiStatusDisplay(); updateBluetoothStatusDisplay(); updateGPSStatusDisplay(); updateNFCStatusDisplay(); getActivity().registerReceiver(receiver, filter); return view; }
From source file:com.landenlabs.all_devtool.GpsFragment.java
@SuppressWarnings("deprecation") @Override/*from w ww . j ava 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); View rootView = inflater.inflate(R.layout.gps_tab, container, false); m_statusIcon = Ui.viewById(rootView, R.id.gpsStatus); m_statusIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); Ui.viewById(rootView, R.id.gps_clear).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearList(); } }); m_list.clear(); // ---- Get UI components ---- for (int idx = 0; idx != s_maxRows; idx++) m_list.add(null); m_list.set(s_providersRow, new GpsInfo(new GpsItem("Providers"))); m_list.set(s_lastUpdateRow, new GpsInfo(new GpsItem("Last Update"))); m_list.set(s_detailRow, new GpsInfo(new GpsItem("Detail History"))); m_listView = Ui.viewById(rootView, R.id.gpsListView); final GpsArrayAdapter adapter = new GpsArrayAdapter(this.getActivity()); m_listView.setAdapter(adapter); // ---- Setup GPS ---- m_locMgr = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); m_gpsTv = Ui.viewById(rootView, R.id.gps); if (isGooglePlayServicesAvailable()) { m_locationRequest = new LocationRequest(); m_locationRequest.setInterval(GPS_INTERVAL); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); // Priority needs to match permissions. // Use LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> // Use LocationRequest.PRIORITY_HIGH_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_googleApiClient = new GoogleApiClient.Builder(this.getActivity()).addApi(LocationServices.API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); m_gpsTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { m_gpsMonitor = !m_gpsMonitor; view.setSelected(m_gpsMonitor); addMsgToDetailRow(s_colorMsg, m_gpsMonitor ? "Start Monitor" : "Stop Monitor"); showProviders(); } }); } else { m_gpsTv.setText("Need Google Play Service"); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { m_locMgr.addGpsStatusListener(this); } /* http://stackoverflow.com/questions/11398732/how-do-i-receive-the-system-broadcast-when-gps-status-has-changed <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <receiver android:name=".GpsReceiver"> <intent-filter> <action android:name="android.location.GPS_ENABLED_CHANGE" /> <action android:name="android.location.PROVIDERS_CHANGED" /> </intent-filter> </receiver> */ // GpsReceiver m_gpsReceiver = new GpsReceiver(); m_intentFilter.addAction(GpsReceiver.GPS_ENABLED_CHANGE_ACTION); if (Build.VERSION.SDK_INT >= 19) { m_intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); } m_intentFilter.addAction(GpsReceiver.GPS_FIX_CHANGE_ACTION); m_intentFilter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); showProviders(); // TODO - get available providers getCheckBox(rootView, R.id.gpsFuseCb, FUSED_PROVIDER); getCheckBox(rootView, R.id.gpsGPSCb, LocationManager.GPS_PROVIDER); getCheckBox(rootView, R.id.gpsNetwkCb, LocationManager.NETWORK_PROVIDER); getCheckBox(rootView, R.id.gpsLowPwrCb, LocationManager.PASSIVE_PROVIDER); getCheckBox(rootView, R.id.gpsStatusCb, STATUS_CB); for (CheckBox cb : m_providersCb.values()) { cb.setOnClickListener(this); } initLastUpdate(); // Expand All for (int idx = 0; idx != s_maxRows; idx++) m_listView.expandGroup(idx); return rootView; }