I want to send sms using ionic framework.I install this plugin:
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
In javascript:
document.addEventListener("deviceready", function() {
var options = {
replaceLineBreaks: false, // true to replace \n by a new line, false by default
android: {
intent: '' // send SMS with the native android SMS messaging
//intent: '' // send SMS without open any other app
//intent: 'INTENT' // send SMS inside a default SMS app
}
};
$cordovaSms
.send('+919915768727', 'This is some dummy text', options)
.then(function() {
alert('Success');
// Success! SMS was sent
}, function(error) {
alert('Error');
// An error occurred
});
});
Message is not send.this will alert error.I dont know where I am wrong.
cordova version: 5.2.0
Ionic version: 1.6.4
you have place the function of $cordovaSMS in an $ionicPlatform function as
$ionicPlatform.ready(function(){
$cordovaSms
.send($scope.form.number, $scope.form.message, options)
.then(function(result) {
console.log(result);
}, function(error) {
console.log(error);
})
})
and I am uploading a demo project for you in git hub follow the steps in readme.md file of github
Having any queries replay back
Related
I am tring to do push notification on my cordova android app with Cordova plugin for Firebase Cloud Messaging plugin. I have created and registered app in Google firebase console and downloaded google-services.json file and kept it in my project root folder. Then I am trying the functions provided in the plugin documentation on device ready but did not get the device token, it is blank. My cordova android version is 9.1.0. Can someone tell me why the device token is not generated? Please help me. My js code is below:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
cordova.plugins.firebase.messaging.onMessage(function (payload) {
console.log("New foreground FCM message: ", payload);
});
cordova.plugins.firebase.messaging.onBackgroundMessage(function (payload) {
console.log("New background FCM message: ", payload);
});
cordova.plugins.firebase.messaging.requestPermission({ forceShow: true }).then(function ()
{
console.log("You'll get foreground notifications when a push message arrives");
});
cordova.plugins.firebase.messaging.getToken().then(function (token) {
alert("Got device token: ", token);
});
/*cordova.plugins.firebase.messaging.onTokenRefresh(function () {
console.log("Device token updated");
});*/
cordova.plugins.firebase.messaging.createChannel({
id: "mypushid",
name: "Push channel",
importance: 3
});
}
I create ionic 3 application and I want send and receive data between two app with hotspot network and I try to create client and server socket on each app with this plugin :
npm i cordova-plugin-chrome-apps-socket
and try with this code :
declare var chrome;
and use plugin in ionViewDidLoad :
ionViewDidLoad(){
chrome.sockets.tcp.create({}, createInfo => {
let socketTcpId = createInfo.socketId;
chrome.sockets.tcp.connect(socketTcpId, "127.0.0.1", 12345, result => {
console.log("Connected to server");
});
});
}
and run :
ionic cordova build android
and install and run apk file on genymotion but console give me this error :
chrome is not defined
and also I try with this way :
ionViewDidLoad(){
(<any>window).chrome.sockets.tcp.create({}, createInfo => {
socketTcpId = createInfo.socketId;
chrome.sockets.tcp.connect(socketTcpId, "127.0.0.1", 12345, result => {
console.log("Connected to server");
});
});
}
but console give me last error
You need to install following TCP library
cordova-plugin-chrome-apps-sockets-tcp
I try to use phonegap-plugin-push 2.x. Registration event fires correctly in browser and in PhoneGap Developer app but nothing happens in application obtained from build.phonegap.com. Init is pastedet in deviceready part of code. I'll appreciate any suggestions.
<!--Initializing Push Notification-->
const push = PushNotification.init({
android: {
senderID: "12345....." // the same without this line
},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
push.on('registration', function(data) {
obj.regid = data.registrationId;
alert(data.registrationId); // no alert in built app
});
Have you included google-services.json, as required by version 2+ of the push plugin?
I'm using this plugin in my ionic 1 project.
Follow what author wrote here.
I can get token from Google Firebase when i run my app on device, but I don't understand how register and get messages and push notifications..
Anyone have examples on how get push notifications directly from Google Firebase?
I have worked with the plugin cordova-plugin-fcm, with this plugin I used the code below to receive push notifications,the plugin documentation, you will need to download the file google-services.json and copy it to your android platform , make sure you have the following installed on you sdk, the documentation on the plugin has a lot of detail
Android Support Library version 23 or greater
Android Support Repository version 20 or greater
Google Play Services version 27 or greater
Google Repository version 22 or greater
FCMPlugin.getToken(
function (token) {
console.log(token);
},
function (err) {
console.log('error retrieving token: ' + err);
}
);
FCMPlugin.onNotification(
function(data){
console.log(JSON.stringify(data));
if(data.wasTapped){
console.log("=====================alert received on device tray and tapped by the user================"+JSON.stringify(data));
}else{
console.log("=====================alert received when app is open================"+JSON.stringify(data));
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
I'm running example code (found below) through phonegap build to produce an android apk.
https://github.com/phonegap-build/FacebookConnect/blob/master/example/Simple/index.html
When I try to log into facebook through the app on an android device (with the facebook app installed), I get this error:
Invalid android_key parameter J4INwYsuTyQ_LJc1d3WZ2HReg7M does not match any allowed android key. Configure your app key hashes at http://developers.facebook.com/apps/'app id'
I have copy-pasted this key into the key hashes section of my app's android settings but it still throws the same error when I try to log in using the app.
How can I get this app to log into facebook successfully?
OR: What is another way to enable an android app to log into facebook using phonegap?
Here are some things I have done:
In my facebook app's settings:
Set 'Package name' to the 'widget id' found in my phonegap config.xml.
Set 'Class name' to the Package name with '.ProjectActivity' appended to it.
Enabled 'Single Sign on' and disabled 'Deep linking'.
Made the app open to the public (through the 'Status & Review' section.
In my phonegap config.xml (found in the /www directory in phonegap project):
Entered APP_ID as the ID found in my facebook app dashboard
Entered APP_NAME as the 'Namespace' found in my facebook app settings
In my phonegap build app settings:
Made a keystore (using this answer: https://stackoverflow.com/a/19315975/1696114) and used it to generate a release apk.
I think you should use facebook phonegap plugin as your authentication.
Download and install into your cordova project.
https://github.com/phonegap/phonegap-facebook-plugin
Use this command to install it.
cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="xxxxxxxxxxxxx" --variable APP_NAME=“xxxxxxxx”
Then setup your facebook app here:
http://developers.facebook.com/apps/
Then make sure you have this script in your project.
cdv-plugin-fb-connect.js
facebook-js-sdk.js
After that, paste this code into your main script
if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');
FB.Event.subscribe('auth.login', function(response) {
//alert('auth.login event');
});
FB.Event.subscribe('auth.logout', function(response) {
//alert('auth.logout event');
});
FB.Event.subscribe('auth.sessionChange', function(response) {
//alert('auth.sessionChange event');
});
FB.Event.subscribe('auth.statusChange', function(response) {
//alert('auth.statusChange event');
});
function getSession() {
alert("session: " + JSON.stringify(FB.getSession()));
}
function getLoginStatus() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
alert('logged in');
} else {
alert('not logged in');
}
});
}
var friendIDs = [];
var fdata;
function logout() {
FB.logout(function(response) {
alert('logged out');
window.location.replace("#login");
});
}
function login() {
FB.login(
function(response) {
if (response.authResponse) {
alert('logged in');
FB.api('/me', function(me) {
if (me.id) {
localStorage.id = me.id;
localStorage.email = me.email;
localStorage.name = me.name;
window.location.replace("#home");
}
else {
alert('No Internet Connection. Click OK to exit app');
navigator.app.exitApp();
}
});
} else {
alert('not logged in');
}
}, {
scope: "email"
});
}
document.addEventListener('deviceready', function() {
try {
//alert('Device is ready! Make sure you set your app_id below this alert.');
FB.init({
appId: "appid",
nativeInterface: CDV.FB,
useCachedDialogs: false
});
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}, false);
use login() to login . Enjoy!!
I successfully made an app which can log into facebook by using the phonegap-facebook-plugin and by building my cordova/phonegap project locally.
I made a new cordova project and added the android platform for this project, following the instructions here: http://docs.phonegap.com/en/3.4.0/guide_overview_index.md.html#Overview
In doing this I discovered I had made my previous project using an older cordova version (3.1) un-intentionally and that I hadn't installed the cordova command line interface. There may have been other issues with the way I made my first project.
I then added the phonegap-facebook-plugin found here: https://github.com/phonegap/phonegap-facebook-plugin using this command (from my project location):
cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="xxxxxxxxxxxxx" --variable APP_NAME=“xxxxxxxx”
(replacing APP_ID value with my facebook app id and APP_NAME value with my app's namespace).
I then replaced my index.html with the example index file found at the phonegap-facebook-plugin github page + /blob/master/example/Simple/index.html (replacing the app_id value with my app id).
I then ran the app straight to my android device using:
cordova run android
In this app, I'm able to use the interface provided by the example to login, post to my own or friends' walls etc. Using this new project (with updated cordova version) I may be able to use phonegap build but I haven't tried yet.
Thanks to Dato' Mohammad Nurdin for the suggestion to use this plugin.