I am creating an android APP using Ionic framework,I want to launch an external app from my app.
I included the acces-orgin in the config.xml
<access origin="speedtest:*" launch-external="yes"/>
I am using the following code
<button class="button button-positive" ng-click="btnClick()"> Launch Speed Test</button>
In My app.js
function onDeviceReady() {
var scheme;
// Don't forget to add the org.apache.cordova.device plugin!
if(device.platform === 'iOS') {
scheme = 'speedtest://';
}
else if(device.platform === 'Android') {
scheme = 'org.zwanoo.android.speedtest';
}
$scope.btnClick = function() {
appAvailability.check(
scheme, // URI Scheme
function() { // Success callback
window.open('speedtest://', '_system', 'location=no');
console.log('Speedtest is available');
},
function() { // Error callback
//alert("not available");
window.open('https://play.google.com/store/apps/details?id=org.zwanoo.android.speedtest', '_system', 'location=no');
console.log('Speedtest is not available');
}
);
}
}
the following line is not working and it does not throw any error in the console.
window.open('speedtest://', '_system', 'location=no');
Please guide me .
You can start an external application using third party plugin. Please follow the link below
Plugin for check or launch other application in android device
e.g.
Check application for installed
navigator.startApp.check("com.application.name", function(message) { /* success */
console.log(message); // => OK
},
function(error) { /* error */
console.log(error);
});
Start external application
navigator.startApp.start("com.application.name", function(message) { /* success */
console.log(message); // => OK
},
function(error) { /* error */
console.log(error);
});
Related
I am getting an error when I try to use the cordova-plugin-apprate plugin. Where I expect to see the in-app-rating occur, instead it seems to be trying to launch file:///android_asset/www/null.
My react code:
import "./App.css";
import React, { useState } from "react";
import AppRate from "cordova-plugin-apprate";
function App() {
console.log(`App starting...`);
const handleClick = () => {
console.log(`handleClick`);
const ref = window.open("http://www.google.com", "_self");
console.log(`opened window`);
};
const rateClick = () => {
console.log(`rateClick`);
AppRate.setPreferences({
storeAppUrl: {
ios: "blah.blah.blah",
android: "market://details?id=blah.blah.blah",
},
reviewType: {
ios: "AppStoreReview",
android: "inAppBrowser",
},
simpleMode: true,
showPromptForInAppReview: false,
customLocale: {
title: "My Title",
message: "My Message",
rateButtonLabel: "Rate It Now...",
cancelButtonLabel: "No, Thanks...",
laterButtonLabel: "Remind Me Later...",
},
callbacks: {
onButtonClicked: function (buttonIndex) {
console.log(`Button Clicked ${buttonIndex}`);
switch (buttonIndex) {
case 1:
console.log(`B1`);
break;
case 2:
console.log(`B2`);
break;
case 3:
console.log(`B3`);
break;
}
},
},
openUrl: function (url) {
console.log(`openUrl to ${url}`);
let safariAvailable = false;
if (window.SafariViewController) {
window.SafariViewController.isAvailable(function (available) {
safariAvailable = available;
});
}
if (!safariAvailable) {
console.log(`no safari, must be a droid...`);
window.open(url, "_blank", "location=yes");
} else {
window.SafariViewController.show(
{
url: url,
barColor: "#0000ff", // on iOS 10+ you can change the background color as well
controlTintColor: "#00ffff", // on iOS 10+ you can override the default tintColor
tintColor: "#00ffff", // should be set to same value as controlTintColor and will be a fallback on older ios
},
// this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
function (result) {},
function (msg) {}
);
}
},
});
AppRate.promptForRating();
};
return (
<div className="App">
<header className="App-header">
<p>Hello from React App</p>
<button onClick={handleClick}>Open Google</button>
<button onClick={rateClick}>Rate Me</button>
</header>
</div>
);
}
export default App;
When the 'Rate Me' button is clicked, the expected behavior occurs, i.e. the following options are displayed:
Please Review Menu
However, when I select the 'Rate it Now...' button i get:
load null file
Which is not the expected behavior. From everything I have read about this, I should see the in-app rating.
Also the log messages do show that openUrl is called with null as the argument and that button 3 was clicked. I assume button 3 is the rate button but that the null value for the url is incorrect.
I did try changing the reviewType.android value from "InAppBrowser" to "InAppReview" but the behavior was the same. I have the following plugins installed:
cordova-plugin-apprate
cordova-plugin-dialogs
cordova-plugin-inappbrowser
cordova-plugin-nativestorage
cordova-plugin-whitelist
I am developing an app from ionic-1. I also implemented facebook login plugin. I've followed this steps. I have no errors, but when I click on the facebook button, it doesn't work, no errors displaying. I use alert in every error catch but no alert will be displayed.
NOTE: I am running in an real android device because they said that native plugin will not work in browser.
Please help me because Im working with my thesis. Thanks to all of you!
Here's my code:
.controller('CreateAccountCtrl', ['$scope','$http','$state','$q','UserService','$stateParams', '$ionicLoading','$timeout','$ionicPopup',function($scope, $http,$state,$q, UserService,$stateParams,$ionicLoading,$timeout,$ionicPopup){
$scope.$on('$ionicView.beforeEnter', function(e){
$ionicLoading.show({
animation: 'fade-in', showBackdrop: true
});
});
$scope.$on('$ionicView.afterEnter', function(e){
$ionicLoading.hide();
$scope.formData = {};
$scope.showAlert = function(ttl,msg){
var alertPopup = $ionicPopup.alert({
title: ttl,
template: msg
});
};
});
// facebook
// This is the success callbak from the login method
var fbLoginSuccess = function(response){
if(!response.authResponse){
fbLoginError("Cannot find the authResponse");
return;
}
var authResponse = response.authResponse;
getFacebookProfileInfo(authResponse)
.then(function(profileInfo){
// store user data on local storage
UserService.setUser({
authResponse: authResponse,
userID: profileInfo.id,
name: profileInfo.name,
email: profileInfo.email,
picture: "http://graph.facebook.com/" + authResponse.userID + "/picture?type=large"
});
$ionicLoading.hide();
$state.go('app.home');
}, function(fail){
alert(fail);
// Fail get profile info
console.log('Profile Info Fail', fail);
});
};
// This is the fail callback from the login method
var fbLoginError = function(error){
console.log('fbLoginError', error);
alert(error);
$ionicLoading.hide();
};
// This method is to get the user profile info from the facebook api
var getFacebookProfileInfo = function(authResponse){
var info = $q.defer();
facebookConnectPlugin.api('/me?fields=email,name&access_token=' + authResponse.accessToken, null,
function(response){
alert(response);
console.log(response);
info.resolve(response);
},
function(response){
console.log(response);
alert(response);
info.reject(response);
}
);
return info.promise;
};
// This method is executed when the user press the "Login with faceboook" button
$scope.facebookSignIn = function(){
alert(1);
facebookConnectPlugin.getLoginStatus(function(success){
if(success.status === 'connected'){
// The user is logged in and has authenticated your app, and response.authResponse supplies
// the user's ID, a valid access token, a signed request, and the time the access token
// and signed request each expire
console.log('getLoginStatus', success.status);
alert(success.status);
// Check if we have our user saved
var user = UserService.getUser('facebook');
if(!user.userID){
getFacebookProfileInfo(success.authResponse)
.then(function(profileInfo){
UserService.setUser({
authResponse: success.authResponse,
userID: profileInfo.id,
name: profileInfo.name,
email: profileInfo.email,
picture : "http://graph.facebook.com/" + success.authResponse.userID + "/picture?type=large"
});
$state.go('app.home');
}, function(fail){
console.log('Profile info fail', fail);
alert(fail);
});
}else{
$state.go('app.home');
}
}else{
// If (success.status === 'not_authorized') the user is logged in to Facebook,
// but has not authenticated your app
// Else the person is not logged into Facebook,
// so we're not sure if they are logged into this app or not.
console.log('getLoginStatus', success.status);
alert(success.status);
$ionicLoading.show({
template: 'Logging in...'
});
facebookConnectPlugin.login(['email','public_profile'], fbLoginSuccess, fbLoginError);
}
});
};
}]);
And in my html
<a class="facebook-sign-in button button-block button-facebook" ng-click="facebookSignIn()">
<i class="icon ion-social-facebook"></i>
Sign in using facebook
</a>
APP_NAME="must be facebook application name that's created on facebook developer not your app name"
APP_ID=facebook app id.
Install with facebook v4
$ cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"
$rootScope.loginFacebook = function() {
$cordovaFacebook.login(["public_profile", "email", "user_birthday", "user_photos"]).then(function(success){
console.info(success.status);
if (success.status === 'connected') {
var checkrequest = {
'AuthSession[device_token]': $localStorage.device_token
}
appname.check(checkrequest).then(function(response) {
console.log(response);
if (response.key == "NOAUTH") {
$state.go('main.allowPush')
}
})
} else if (success.status === 'not_authorized') {
console.info('the user is logged in to Facebook but has not
authenticated your app')
} else {
console.info('the user is nott logged in to Facebook')
}
}, function(error) {
console.info(error);
});
}
i use this tutorial https://github.com/nraboy/ng-cordova-facebook-example but this example is not implemented the function of logout ,i add this code:
facebookExample.controller("LogoutController", function($scope, $http, $localStorage, $location) {
$scope.logout = function() {
$cordovaFacebook.logout();
}, function(error) {
alert("There was a problem signing in! See the console for logs");
console.log(error);
}
});
profile.html :
<ion-nav-buttons side="right">
<button class="button icon-left ion-log-out button-stable" ng-controller="LogoutController" ng-click="logout()">Logout</button>
</ion-nav-buttons>
but i found any result
Your code is invalid javascript... lots of parsing errors. also, you dont need another controller just for logout. The fact that a user is logged in is based upon an access token in localstorage, just wipe it and go to another state.. update your profile controller to this:
facebookExample.controller("ProfileController", function($scope, $http, $localStorage, $location) {
$scope.init = function() {
if($localStorage.hasOwnProperty("accessToken") === true) {
$http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id,name,gender,location,website,picture,relationship_status", format: "json" }}).then(function(result) {
$scope.profileData = result.data;
}, function(error) {
alert("There was a problem getting your profile. Check the logs for details.");
console.log(error);
});
} else {
alert("Not signed in");
$location.path("/login");
}
};
$scope.logout = function(){
delete $localStorage.accessToken;
$location.path("/login");
};
});
profile.html:
<ion-nav-buttons side="right">
<button class="button icon-left ion-log-out button-stable" ng-click="logout()">Logout</button>
</ion-nav-buttons>
I'm following this tutorial for having banner ads in my android application.
https://blog.nraboy.com/2014/06/using-admob-ionicframework/
The problem is that I get an error callback from the plugin which is only telling me :
Invalid action
I ran the cordova plugin add for the plugin, I modified the admob publisher id, I used the sample code from the tutorial right above but it always get stuck in the second callback function which is the error case callback.
Here is the code I used :
var admobApp = angular.module('myapp', ['ionic'])
.run(function($ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
if(window.plugins && window.plugins.AdMob) {
var admob_key = device.platform == "Android" ? "ANDROID_PUBLISHER_KEY" : "IOS_PUBLISHER_KEY";
var admob = window.plugins.AdMob;
admob.createBannerView(
{
'publisherId': admob_key,
'adSize': admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function() {
admob.requestAd(
{ 'isTesting': false },
function() {
admob.showAd(true);
},
function() { console.log('failed to request ad'); }
);
},
function() { console.log('failed to create banner view'); }
);
}
});
});
I'm new to Ionic and Cordova, so I'm sure I'm missing something basic, but my problem is a packaged APK does not play sounds on an Android device. I can get the sound to play in the Ripple emulator just fine with the following code:
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.playStartBell = function () {
var media = new Media('media/startBell.mp3', function () {
console.log('good');
}, function (err) {
console.log('bad: ', err);
});
media.play();
},
$scope.playStopBell = function () {
var media = new Media('media/stopBell.mp3', function () {
console.log('good');
}, function (err) {
console.log('bad: ', err);
});
media.play();
}
}])
I've used Cordova to install the media plugin: $cordova plugin add org.apache.cordova.media
According to this SO post, a value needs to be added to the config.xml, but I'm not sure how to do it properly for Ionic/Cordova.
Turns out that you have specify path starting with the /android_asset/www prefix like so:
/android_asset/www/
So changing my code to the following worked. Note you'll want to detect what device you're running on to determine the appropriate location.
.controller('MainCtrl', ['$scope', function ($scope) {
///android_asset/www/
$scope.playStartBell = function () {
var media = new Media('/android_asset/www/media/startBell.mp3', function () {
console.log('good');
}, function (err) {
console.log('bad: ', err);
});
media.play();
},
$scope.playStopBell = function () {
var media = new Media('/android_asset/www/media/stopBell.mp3', function () {
console.log('good');
}, function (err) {
console.log('bad: ', err);
});
media.play();
}
}])