抱歉,该网页目前还不存在中文版本,请继续浏览其他网页!

Permissions

The xwalk_permissions field is a Crosswalk extension to the W3C manifest. It is used to set permissions in the AndroidManifest.xml file when packaging an application for Crosswalk on Android.

This is necessary because Android applications cannot request permissions at runtime: all the permissions required by the application must be granted during installation. In other contexts (Crosswalk Tizen, embedding API), this field is ignored.

Note: If you are loading an application from a manifest with the embedding API, you will have to manually specify permissions for Crosswalk in AndroidManifest.xml. See the section below for guidance on which Android permissions are required by Crosswalk's web APIs.

Effect on Android packaging

The crosswalk-pkg tool translates the permissions or xwalk_permissions field in manifest.json into <android:uses-permission> elements in AndroidManifest.xml.

For example, given the following manifest:

{
  "name": "simple",
  "start_url": "index.html",
  "xwalk_permissions": [
    "Contacts",
    "Geolocation",
    "Messaging",
    "Vibration"
  ],
  "icons": [{
    "src": "icon96.png",
    "type": "image/png",
    "sizes": "96x96",
    "density": "2.0"
    }
  ]
}

...and this crosswalk-pkg command line:

crosswalk-pkg <Path to directory that contains a web app>

...the following AndroidManifest.xml permission elements are generated:

<!-- permissions always added during packaging -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<!-- permissions added due to the "permissions" manifest field -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.VIBRATE"/>

Note that the crosswalk-pkg tool always adds a default set of permissions (the first group in the example above). Only the second group of permissions are the ones added because of the presence of the xwalk_permissions field in the manifest. The mappings from permissions in the manifest to Android permissions are shown in the table in the next section.

Permissions required by API

If you want to use some of Crosswalk's web APIs in an application, you may need to add permissions to AndroidManifest.xml to make those APIs accessible. You can either do this in manifest.json when packaging the web app, or manually (if you are using the embedding API).

The table below shows which web APIs require which permissions.

Crosswalk web API AndroidManifest.xml permission(s)
Contacts android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
Geolocation android.permission.ACCESS_FINE_LOCATION
Messaging android.permission.READ_SMS
android.permission.READ_PHONE_STATE
android.permission.RECEIVE_SMS
android.permission.SEND_SMS
android.permission.WRITE_SMS
Vibration android.permission.VIBRATE

For example, you may have an Android application which embeds Crosswalk, and want to use the JavaScript Vibration API in the web application part of the app. In this case, you would need to manually add this permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.VIBRATE"/>