Merge "docs: Added note about permission/feature changes with network/GPS." into nyc-dev

This commit is contained in:
Kevin Hufnagle
2016-09-13 05:49:28 +00:00
committed by Android (Google) Code Review
4 changed files with 105 additions and 31 deletions

View File

@@ -133,36 +133,66 @@ notifications and the third is the minimum change in distance between notificati
both to zero requests location notifications as frequently as possible. The last parameter is your both to zero requests location notifications as frequently as possible. The last parameter is your
{@link android.location.LocationListener}, which receives callbacks for location updates.</p> {@link android.location.LocationListener}, which receives callbacks for location updates.</p>
<p>To request location updates from the GPS provider, <p>To request location updates from the GPS provider, use {@link
substitute <code>GPS_PROVIDER</code> for <code>NETWORK_PROVIDER</code>. You can also request android.location.LocationManager#GPS_PROVIDER} instead of {@link
location updates from both the GPS and the Network Location Provider by calling {@link android.location.LocationManager#NETWORK_PROVIDER}. You can also request
android.location.LocationManager#requestLocationUpdates requestLocationUpdates()} twice&mdash;once location updates from both the GPS and the Network Location Provider by calling
for <code>NETWORK_PROVIDER</code> and once for <code>GPS_PROVIDER</code>.</p> {@link android.location.LocationManager#requestLocationUpdates
requestLocationUpdates()} twice&mdash;once for {@link
android.location.LocationManager#NETWORK_PROVIDER} and once for {@link
android.location.LocationManager#GPS_PROVIDER}.</p>
<h3 id="Permission">Requesting User Permissions</h3> <h3 id="Permission">Requesting User Permissions</h3>
<p>In order to receive location updates from <code>NETWORK_PROVIDER</code> or <p>
<code>GPS_PROVIDER</code>, you must request user permission by declaring either the {@code In order to receive location updates from {@link
ACCESS_COARSE_LOCATION} or {@code ACCESS_FINE_LOCATION} permission, respectively, in your Android android.location.LocationManager#NETWORK_PROVIDER} or {@link
manifest file. For example:</p> android.location.LocationManager#GPS_PROVIDER}, you must request the user's
permission by declaring either the {@code ACCESS_COARSE_LOCATION} or {@code
ACCESS_FINE_LOCATION} permission, respectively, in your Android manifest file.
Without these permissions, your application will fail at runtime when
requesting location updates.
</p>
<p>
If you are using both {@link
android.location.LocationManager#NETWORK_PROVIDER} and {@link
android.location.LocationManager#GPS_PROVIDER}, then you need to request only
the {@code ACCESS_FINE_LOCATION} permission, because it includes permission
for both providers. (Permission for {@code ACCESS_COARSE_LOCATION} includes
permission only for {@link
android.location.LocationManager#NETWORK_PROVIDER}.)
</p>
<p class="note">
<strong>Note:</strong> If your app targets Android 5.0 (API level 21) or
higher, you must also declare that your app uses the
<code>android.hardware.location.network</code> or
<code>android.hardware.location.gps</code> hardware feature in the manifest
file, depending on whether your app receives location updates from {@link
android.location.LocationManager#NETWORK_PROVIDER} or from {@link
android.location.LocationManager#GPS_PROVIDER}. If your app receives location
information from both of these providers, you need to declare that the app
uses both <code>android.hardware.location.network</code> and
<code>android.hardware.location.gps</code>.
</p>
<p>
The following code sample demonstrates how to declare the permission and
hardware feature in the manifest file of an app that reads data from the
device's GPS:
</p>
<pre> <pre>
&lt;manifest ... &gt; &lt;manifest ... &gt;
&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
... ...
&lt;!-- Needed only if your app targets Android 5.0 (API level 21) or higher. --&gt;
&lt;uses-feature android:name="android.hardware.location.gps" /&gt;
...
&lt;/manifest&gt; &lt;/manifest&gt;
</pre> </pre>
<p>Without these permissions, your application will fail at runtime when requesting
location updates.</p>
<p class="note"><strong>Note:</strong> If you are using both <code>NETWORK_PROVIDER</code> and
<code>GPS_PROVIDER</code>, then you need to request only the {@code ACCESS_FINE_LOCATION}
permission, because it includes permission for both providers. (Permission for {@code
ACCESS_COARSE_LOCATION} includes permission only for <code>NETWORK_PROVIDER</code>.)</p>
<h2 id="BestPerformance">Defining a Model for the Best Performance</h2> <h2 id="BestPerformance">Defining a Model for the Best Performance</h2>
<p>Location-based applications are now commonplace, but due to the less than optimal <p>Location-based applications are now commonplace, but due to the less than optimal
@@ -404,9 +434,10 @@ don't have a device, you can still test your location-based features by mocking
the Android emulator. There are three different ways to send your application mock location the Android emulator. There are three different ways to send your application mock location
data: using Android Studio, DDMS, or the "geo" command in the emulator console.</p> data: using Android Studio, DDMS, or the "geo" command in the emulator console.</p>
<p class="note"><strong>Note:</strong> Providing mock location data is injected as GPS location <p class="note"><strong>Note:</strong> Providing mock location data is injected
data, so you must request location updates from <code>GPS_PROVIDER</code> in order for mock location as GPS location data, so you must request location updates from {@link
data to work.</p> android.location.LocationManager#GPS_PROVIDER} in order for mock location data
to work.</p>
<h3 id="MockAVD">Using Android Studio</h3> <h3 id="MockAVD">Using Android Studio</h3>

View File

@@ -1685,6 +1685,15 @@ densities: '160'
<pre>&lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;</pre> <pre>&lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;</pre>
<p class="note">
<strong>Note:</strong> If your app targets Android 5.0 (API level 21) or
higher and uses the <code>ACCESS_COARSE_LOCATION</code> or
<code>ACCESS_FINE_LOCATION</code> permission in order to receive location
updates from the network or a GPS, respectively, you must also explicitly
declare that your app uses the <code>android.hardware.location.network</code>
or <code>android.hardware.location.gps</code> hardware feature, respectively.
</p>
<p class="table-caption" id="permissions-features"> <p class="table-caption" id="permissions-features">
<strong>Table 2. </strong>Device permissions that imply device hardware use. <strong>Table 2. </strong>Device permissions that imply device hardware use.
</p> </p>
@@ -1736,14 +1745,29 @@ densities: '160'
</tr> </tr>
<tr> <tr>
<td><code>ACCESS_COARSE_LOCATION</code></td> <td><code>ACCESS_COARSE_LOCATION</code></td>
<td><code>android.hardware.location.network</code> <em>and</em> <td>
<br><code>android.hardware.location</code></td> <p>
<code>android.hardware.location</code>
</p>
<p>
<code>android.hardware.location.network</code> (Target API level 20 or
lower only.)
</p>
</td>
<!-- <td></td> --> <!-- <td></td> -->
</tr> </tr>
<tr> <tr>
<td><code>ACCESS_FINE_LOCATION</code></td> <td><code>ACCESS_FINE_LOCATION</code></td>
<td><code>android.hardware.location.gps</code> <em>and</em> <td>
<br><code>android.hardware.location</code></td> <p>
<code>android.hardware.location</code>
</p>
<p>
<code>android.hardware.location.gps</code> (Target API level 20 or lower
only.)
</p>
</td>
<!-- <td></td> --> <!-- <td></td> -->
</tr> </tr>

View File

@@ -154,10 +154,16 @@ application must request the audio capture permission.
&lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt; &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
</pre> </pre>
</li> </li>
<li><strong>Location Permission</strong> - If your application tags images with GPS location <li>
information, you must request location permission: <p><strong>Location Permission</strong> - If your application tags images
with GPS location information, you must request the "fine location"
permission. Note that, if your app targets Android 5.0 (API level 21) or
higher, you also need to declare that your app uses the device's GPS:</p>
<pre> <pre>
&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
...
&lt;!-- Needed only if your app targets Android 5.0 (API level 21) or higher. --&gt;
&lt;uses-feature android:name="android.hardware.location.gps" /&gt;
</pre> </pre>
<p>For more information about getting user location, see <p>For more information about getting user location, see
<a href="{@docRoot}guide/topics/location/strategies.html">Location Strategies</a>.</p> <a href="{@docRoot}guide/topics/location/strategies.html">Location Strategies</a>.</p>

View File

@@ -227,13 +227,19 @@ if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION)
</tr> </tr>
<tr> <tr>
<td>{@link android.Manifest.permission#ACCESS_COARSE_LOCATION}</td> <td>{@link android.Manifest.permission#ACCESS_COARSE_LOCATION}</td>
<td>{@code android.hardware.location} <em>and</em> <br> <td>
{@code android.hardware.location.network}</td> <p>{@code android.hardware.location}</p>
<p>{@code android.hardware.location.network} (Target API level 20 or lower
only.)</p>
</td>
</tr> </tr>
<tr> <tr>
<td>{@link android.Manifest.permission#ACCESS_FINE_LOCATION}</td> <td>{@link android.Manifest.permission#ACCESS_FINE_LOCATION}</td>
<td>{@code android.hardware.location} <em>and</em> <br> <td>
{@code android.hardware.location.gps}</td> <p>{@code android.hardware.location}</p>
<p>{@code android.hardware.location.gps} (Target API level 20 or lower
only.)</p>
</td>
</tr> </tr>
</table> </table>
@@ -246,6 +252,13 @@ if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION)
required ({@code android:required="false"}). required ({@code android:required="false"}).
</p> </p>
<p class="note">
<strong>Note:</strong> If your app targets Android 5.0 (API level 21) or
higher and uses the <code>ACCESS_COARSE_LOCATION</code> or
<code>ACCESS_FINE_LOCATION</code> permission, users can still install your
app on a TV device, even if the TV device doesn't have a network card or a GPS
receiver.
</p>
<h3 id="check-features">Checking for hardware features</h2> <h3 id="check-features">Checking for hardware features</h2>