docs(): added docs for installing apk / ipa file from marketplace. closes #57

This commit is contained in:
shnist 2018-12-11 17:11:39 +00:00
parent ab3da281c6
commit 4d70f315df

150
README.md
View File

@ -16,58 +16,77 @@ Requirements
Installation Installation
------------- -------------
$ cordova plugin add cordova-plugin-file-opener2 ```shell
$ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_VERSION={required version} $ cordova plugin add cordova-plugin-file-opener2
$ cordova plugin add cordova-plugin-file-opener2 --variable ANDROID_SUPPORT_VERSION={required version}
```
Usage Usage
------ ------
cordova.plugins.fileOpener2.open( ```javascript
filePath, cordova.plugins.fileOpener2.open(
fileMIMEType, filePath,
{ fileMIMEType,
error : function(){ }, {
success : function(){ } error : function(){ },
} success : function(){ }
); }
);
```
Examples Examples
-------- --------
Open an APK install dialog: Open an APK install dialog:
cordova.plugins.fileOpener2.open( ```javascript
'/sdcard/Download/gmail.apk', cordova.plugins.fileOpener2.open(
'application/vnd.android.package-archive' '/sdcard/Download/gmail.apk',
); 'application/vnd.android.package-archive'
);
```
Install From Market: to install an APK from a market place, such as Google Play or the App Store, you can use an `<a>` tag in combination with the `market://` protocol:
```html
<a href="market://details?id=xxxx" target="_system">Install from Google Play</a>
<a href="itms-apps://itunes.apple.com/app/my-app/idxxxxxxxx?mt=8" target="_system">Install from App Store</a>
```
or in code:
```javascript
window.open("[market:// or itms-apps:// link]","_system");
```
Open a PDF document with the default PDF reader and optional callback object: Open a PDF document with the default PDF reader and optional callback object:
```javascript
cordova.plugins.fileOpener2.open( cordova.plugins.fileOpener2.open(
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf', 'application/pdf',
{ {
error : function(e) { error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message); console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
}, },
success : function () { success : function () {
console.log('file opened successfully'); console.log('file opened successfully');
}
} }
); }
);
```
Open a system modal to open PDF document with one of the already installed app and optional callback object: Open a system modal to open PDF document with one of the already installed app and optional callback object:
```javascript
cordova.plugins.fileOpener2.showOpenWithDialog( cordova.plugins.fileOpener2.showOpenWithDialog(
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf', 'application/pdf',
{ {
error : function(e) { error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message); console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
}, },
success : function () { success : function () {
console.log('file opened successfully'); console.log('file opened successfully');
}
} }
); }
);
```
Notes Notes
------ ------
@ -78,16 +97,17 @@ Notes
- If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co) - If you are wondering what MIME-type should you pass as the second argument to `open` function, [here is a list of all known MIME-types](http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=co)
Android APK installation limitation Android APK installation limitation
--- ---
The following limitations apply when opening an APK file for installation: The following limitations apply when opening an APK file for installation:
- On Android 8+, your application must have the `ACTION_INSTALL_PACKAGE` permission. You can add it by adding this to your app's `config.xml` file: - On Android 8+, your application must have the `ACTION_INSTALL_PACKAGE` permission. You can add it by adding this to your app's `config.xml` file:
``` ```xml
<platform name="android"> <platform name="android">
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android"> <config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
</config-file> </config-file>
</platform> </platform>
``` ```
- Before Android 7, you can only install APKs from the "external" partition. For example, you can install from `cordova.file.externalDataDirectory`, but **not** from `cordova.file.dataDirectory`. Android 7+ does not have this limitation. - Before Android 7, you can only install APKs from the "external" partition. For example, you can install from `cordova.file.externalDataDirectory`, but **not** from `cordova.file.dataDirectory`. Android 7+ does not have this limitation.
@ -99,30 +119,30 @@ The following functions are available in Android platform:
`.uninstall(packageId, callbackContext)` `.uninstall(packageId, callbackContext)`
--- ---
Uninstall a package with its id. Uninstall a package with its id.
```javascript
cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', { cordova.plugins.fileOpener2.uninstall('com.zynga.FarmVille2CountryEscape', {
error : function(e) { error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message); console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
}, },
success : function() { success : function() {
console.log('Uninstall intent activity started.'); console.log('Uninstall intent activity started.');
} }
}); });
```
`.appIsInstalled(packageId, callbackContext)` `.appIsInstalled(packageId, callbackContext)`
--- ---
Check if an app is already installed. Check if an app is already installed.
```javascript
cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', { cordova.plugins.fileOpener2.appIsInstalled('com.adobe.reader', {
success : function(res) { success : function(res) {
if (res.status === 0) { if (res.status === 0) {
console.log('Adobe Reader is not installed.'); console.log('Adobe Reader is not installed.');
} else { } else {
console.log('Adobe Reader is installed.') console.log('Adobe Reader is installed.')
}
} }
}); }
});
```
--- ---
LICENSE LICENSE