A Cordova plugin to get the icon and label of an app based on its package name.
cordova plugin add cordova-plugin-get-app-info
Get app label:
cordova.plugins.GetAppInfo.getAppLabel(function(label) {
console.log(label);
}, function(error) {
console.error(error);
});
Get app icon in Base64 string format:
cordova.plugins.GetAppInfo.getAppIcon(function(base64Icon) {
console.log(base64Icon);
}, function(error) {
console.error(error);
});
In order for the plugin to be injectable into your providers/components and to use it the same way you use Ionic Native plugins, follow these steps:
-
Install the plugin as described in the Install section.
-
Create a Ionic Native wrapper for
cordova-plugin-get-app-info
. A reasonable location for the wrapper issrc/plugins/get-app-info/get-app-info.ts
:import { Injectable } from '@angular/core'; import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; @Plugin({ pluginName: 'GetAppInfo', plugin: 'cordova-plugin-get-app-info', pluginRef: 'cordova.plugins.GetAppInfo', repo: 'https://github.com/esartor/cordova-plugin-get-app-info', platforms: ['Android'] }) @Injectable() export class GetAppInfo extends IonicNativePlugin { @Cordova() getAppIcon(packageName: string): Promise<string> { return; } @Cordova() getAppLabel(packageName: string): Promise<string> { return; } }
Read this guide for a full explanation on how to wrap Cordova plugins with Ionic Native.
-
Inject the plugin into your providers/components and access the
getAppLabel
andgetAppIcon
methods which will return a promise. Example code:import { Injectable } from '@angular/core'; import { Platform } from 'ionic-angular'; import { GetAppInfo } from '../../plugins/get-app-info/get-app-info'; @Injectable() export class MyProvider { constructor( private platform: Platform, private getAppInfo: GetAppInfo ) {} myMethod() { if (this.platform.is(CORDOVA_PLATFORM)) { getAppInfo.getAppIcon('random.package.id').then((base64Icon) => { console.log(base64Icon); }); } } }
- Android
MIT