Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You requirement separated into 2 parts:</p> <p>First is the orientation changes, in <code>AndroidManifest.xml</code>, register the configuration change of orientation for your <code>Activity</code>:</p> <pre><code>&lt;activity android:name=".YourActivity" android:configChanges="orientation"&gt; </code></pre> <p>In <code>YourActivity</code>, override the <code>onConfigurationChanged</code> method:</p> <pre><code>@Override public void onConfigurationChanged(Configuration newConfig) { if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){ // Do your stuffs here as LANDSCAPE mode }else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ //Do your stuffs here as PORTRAIT mode } super.onConfigurationChanged(newConfig); } </code></pre> <p>Second part, location change, register your <code>Activity</code> as the <code>LocationListener</code> and implement the <code>onLocationChanged</code> method:</p> <pre><code>@Override public void onLocationChanged(Location loc) { // Location changed as loc, do things here } </code></pre> <p>And in your <code>onCreate</code>:</p> <pre><code>LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.d(TAG, "GPS is enabled"); GPSListener = new MyLocationListener("GPS"); manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); } else { if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Log.d(TAG, "NETWORK is enabled"); NetworkListener = new MyLocationListener("NETWORK"); manager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 1000, 1, this); } } </code></pre> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload