How to use this SMS plugin in my ionic application? - android

I am trying to use this sms plugin - https://github.com/Ivanezko/Phonegap-SMS in my ionic android application. I am following the Readme documentation to install the plugin. In the second step author asked to do -
Require the plugin module
var smsplugin = cordova.require("info.asankan.phonegap.smsplugin.smsplugin");
What this statement means and where should I include this code to make use of this plugin?
I tried to do this in my controller file and its giving error cordova is not defined.
I tried debugging a little more in an emulator and the error given in the require statement is - module info.asankan.phonegap.smsplugin.smsplugin is not found.

First solution: 1. check that this plugin is wrapped by http://ngcordova.com/.
Second solution: 2. write wrapper = angular factory:
.factory('factoryname', ['$q', '$window','$state', function ($q,$window, $state) {
return {
function1: function () {
var q = $q.defer();
if (!$window.cordova) {
q.reject('Not supported without cordova.js');
} else {
secrettext.function1();
return q.promise;
},
3th solutions: add ['$window'] dependency to module you want use plugin. and use secrettext.function1();
*sectretext its clobbers from plugin xml
4 th solutions copy and paste this js code into you angular code on top of it and use function1();

Related

Ionic capacitor plugin not working for android

I am written a very simple plugin which get all the messages from android device and pack it to response. When I am using npm install ionic-capacitor-sms-access and trying to access messages it just call web method but not the android method. So its not working can someone help me here and tell me what went wrong?
Here is my plugin https://www.npmjs.com/package/ionic-capacitor-sms-access
(Note: only the android folder)
It works, there are two ways to achieve this.
Method 1 (from the official tutorial)
What you need to do is just to keep following that tutorial to the section of 'Custom JavaScript', where shows demonstrates how to use your plugin within your ionic/typescripts codes.
such as:
import { Plugins } from '#capacitor/core';
const { SuperGreatPlugin } = Plugins;
export class CustomSuperPlugin {
constructor() {
}
customAwesomeness() {
SuperGreatPlugin.awesome();
}
}
Notes:
the name of the plugin class, i.e. 'SuperGreatPlugin' must be same with your java class for the plugin.
Method 2 (javascript way)
You can also import your plugin from the npm package you published. But be aware of the first line of the generated definitions.ts, declare module "#capacitor/core". This means you have to find your plugin from the specific module, here it is 'Plugins' as other plugins usage.
The following is the method 2:
import { SuperGreatPlugin } from 'YOUR_PLUGIN_NPM_PACKAGE';
async pluginEcho() {
await Plugins.SuperGreatPlugin.echo({value: 'bla bla bla'})
}
call the function pluginEcho() in your ionic page.
When I started I head really trouble distinguishing the web and native plugin but finally I understand that they are completely separated.
I recommend to rename the exported web plugin object in your web.ts file and add Web in the name. For me this was also necessary in order to not have compile errors.
TS2308: Module './definitions' has already exported a member named 'YourPlugin'. Consider explicitly re-exporting to resolve the ambiguity.
If you want to use your web plugin you import and use it like:
import { YourWebPlugin } from 'YOUR_PLUGIN_NPM_PACKAGE';
YourWebPlugin.callSomething();
If you want to use the native plugin you import and use it like:
import { Plugins } from '#capacitor/core';
const { YourPlugin } = Plugins;
YourPlugin.callSomething();
Don't forget to expose your native plugin to your android app project where you use your custom plugin
https://capacitor.ionicframework.com/docs/plugins/android#export-to-capacitor

How to use an external sdk with Nativescript

I'm developping a NativeScript application and want to use the WonderPush SDK. I've already used this SDK into a native Android application, so I tried to create a new plugin to wrap the SDK.
I imported the library in the gradle file, and I tried to call the library from the NativeScript plugin. But the library is empty, if I tried to log it with console.dir, the only result is an quasi-empty object:
export class NativescriptWonderpush extends Common {
init() {
console.dir(com.wonderpush);
// com.wonderpush.sdk.Wonderpush.initialize(app.android.context);
}
}
JS: ==== object dump start ====
JS: sdk: {}
JS: ==== object dump end ====
(The second line com.wonderpush.sdk.Wonderpush.initialize() crash because com.wonderpush.sdk is empty)
Thanks for your help
Native objects may not always be traceable in console like JS objects.
Though you could refer their docs and call the methods you like Or even generate typings if you are using TypeeScript by following the steps given here. The typings ensure that the classes, methods, properties etc., are public and accessible to the JS runtime.

How to launch external app from an ionic4 app

My app is under Ionic 4 for android and I have to open/run/launch external app (for exemple com.google.android.youtube or com.sygic.truck) -> for instance, any installed app.
I tested many options without any success :
InAppBrowserModule (using application://my.package.name).
Cordova plugin lampaa (I didn't find any ways to use it under angular/ts app type).
I tried also webIntent using package option and action option calling the main Activity.
For InAppBrowserModule, i'm stuck with the http:// protocole appended before my app url.
For Lampaa, i'm stuck with the undefined startApp (even after following other threads suggestions).
And for webIntent, I don't think that it's relevent for my issue.
Any suggestions ?
Thanks in advance !
[EDIT]
I finally make it works !
You can use one of those 2 lines :
this.iab.create('android-app://com.google.android.youtube',"_system");
window.open('android-app://com.google.android.youtube',"_system");
You can replace com.google.android.youtube by any application package name !
You can check if the user is on Android, have the app installed and later open it as follow:
constructor(
private platform: Platform, // from 'ionic-angular'
private appAvailability: AppAvailability, // from '#ionic-native/app-availability'
private iab: InAppBrowser, // from '#ionic-native/in-app-browser'
) {}
openYoutube() {
const package = "com.google.android.youtube"
if(this.platform.is('android')) {
this.appAvailability.check(package)
.then(()=> {
this.iab.create('android-app://'+package, '_system', 'location=yes')
})
.catch(()=> {
// not installed
)
} else {
// not on Android
}
}
For ionic 4 we can use
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
You can use the following cordova plugin to check if other apps are installed and launch them.
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
Simple Cordova plugin to see if other apps are installed and launch them.

cordova.plugins.locationManager.enableBluetooth() Not working in android

I am trying to enable my phone bluetooth via ionic app. I am calling something like this:
cordova.plugins.locationManager.enableBluetooth()
But not enabling and making any error also. Following is my app.js code. Please help out.
import {App, Platform} from 'ionic-framework/ionic';
import {TabsPage} from './pages/tabs/tabs';
#App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
static get parameters() {
return [[Platform]];
}
constructor(platform) {
this.rootPage = TabsPage;
platform.ready().then(() => {
StatusBar.backgroundColorByName('red');
console.log("App starting.");
cordova.plugins.locationManager.enableBluetooth();
});
}
}
Is there anything I am missing. My phone is One Plus One.
UPDATE:
Is there any particular configuration I have to in device to achieve
this in develop mode
App technical info
Ionic 2 & Angular 2
Plugin : com.unarin.cordova.beacon (Link)
I resolved this myself. Seems to be issue was with petermetz/cordova-plugin-ibeacon, I was using 25days older plugin.
First removed the existing plugin by running by going into project root folder:
sudo cordova plugin rm com.unarin.cordova.beacon
Then again added the plugin (basically I updated my plugin):
sudo cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git
After that everything started working fine.
Thanks.

Phonegap - Ignore font-size display setting on Android

I'm having an issue with some android devices when changing the font-size display setting through configuration.
In web browser my app is simple ignoring this. This is true for some other mobiles too.
But with some specific mobiles (like Motorola G or X) changing this config also affects my Phonegap app.
I don't know how to avoid this to make the app look consistent
I've found a solution using this cordova plugin: com.phonegap.plugin.mobile-accessibility
You have to follow installation instructions for the plugin, and then you can use it inside Ionic app. You only have to ensure to call its functions after Cordova 'deviceready' callback (accesed by $ionicPlatform.ready in the example below):
angular.module('app').controller('IndexController', function ($ionicPlatform, $window) {
$ionicPlatform.ready(function(){
if($window.MobileAccessibility){
$window.MobileAccessibility.usePreferredTextZoom(false);
}
});
});
For anyone using Ionic. Documentation is here.
Install
$ ionic cordova plugin add phonegap-plugin-mobile-accessibility
$ npm install --save #ionic-native/mobile-accessibility
Add to module, i.e. app.module.ts
import { MobileAccessibility } from 'ionic-native';
#NgModule({
providers:[MobileAccessibility]
});
In app.component.ts
constructor( mobileAccessibility: MobileAccessibility, platform: Platform) {
platform
.ready()
.then(()=>{
mobileAccessibility.usePreferredTextZoom(false);
});
}

Categories

Resources