Appcelerator Android Camera always make application force close - android

I make an apps using Appcelerator (Titanium SDK).
and I have a problem when open camera, I already set camera permission in tiapp.xml.
And I've try use a source from kitchen Sink titanium.
Here's my code
var win;
function fireUpTheCamera() {
if (Ti.Platform.osname === 'android'|| Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
win.removeEventListener('focus', fireUpTheCamera);
}
Titanium.Media.showCamera({
success:function(event) {
var cropRect = event.cropRect;
var image = event.media;
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
var imageView = Ti.UI.createImageView({
width:win.width,
height:win.height,
image:event.media
});
win.add(imageView);
}
else
{
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function() {
},
error:function(error) {
// create alert
var a = Titanium.UI.createAlertDialog({title:'Camera'});
// set message
if (error.code == Titanium.Media.NO_CAMERA)
{
a.setMessage('Please run this test on device');
}
else
{
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
saveToPhotoGallery:true,
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
}
function cam_basic(_args) {
win = Titanium.UI.createWindow({
title:_args.title
});
if (Ti.Platform.osname === 'android'|| Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
win.addEventListener('focus', fireUpTheCamera);
} else {
fireUpTheCamera();
}
return win;
};
module.exports = cam_basic;
when I finish capture picture and press the OK button, it's always restart application without any error message, also in the log.
I'm using SDK 6.0.0GA.
Please give me some help, and what's wrong with my code.

Before firing up the camera you have to ask the end user for permissions. I'm using this snippet and it works with Ti-5.4.0.
if(Ti.Media.hasCameraPermissions())
fireUpTheCamera();
else
{
Ti.Media.requestCameraPermissions(function(permission)
{
if(permission.success)
fireUpTheCamera();
else
alert('Please Provide permission first');
});
}

Since Titanium sdk 5.1 you need to request runtime permission as well to use the camera.
See here: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-method-requestCameraPermissions

Related

tipsi-stripe 3d secure at react-native

I want to integrate Stripe 3d secure in my react native app. Using this lib: https://github.com/tipsi/tipsi-stripe, and with simple payment it works well. But with 3D I have several problem on iOS and also on Android:
iOS: createCardSource: true (at line 7 crashing the app).(Solved)
iOS: Stucked before redirection on the secure page
Android: How I know if the user paid or decline the payment at the remote page?(At line 27 no any data in the secure3dSourceResponse object)
import stripe from "tipsi-stripe";
paymentRequest = async (mutation, deal) => {
let paymentRequest;
try {
paymentRequest = await stripe.paymentRequestWithCardForm({
...options,
createCardSource: true
});
//iOS and Android gets back different objects.
const threeDSecure = Platform.OS === "android"
? paymentRequest.card.three_d_secure
: paymentRequest.details.three_d_secure;
if (
threeDSecure === "recommended"
|| threeDSecure === "required"
) {
let prefix = Platform.OS === "android"
? `appName://appName/`
: `appName://`;
let secure3dSourceResponse = null;
try {
const { dealFeeUSD } = this.state;
// On iOS the process stucked here, without any error message
secure3dSourceResponse = await stripe.createSourceWithParams({
type: "threeDSecure",
amount: dealFeeUSD || 3000,
currency: "USD",
flow: "redirect",
returnURL: prefix,
card: paymentRequest.sourceId
});
// On android I have no any data in secure3dSourceResponse after Stripe returns from their page.
} catch (error) {
console.log('secure3dSourceResponse', secure3dSourceResponse)
}
} else {
if (paymentRequest && paymentRequest.tokenId) {
this.handlePayDeal(mutation, deal, paymentRequest.tokenId);
}
}
} catch (error) {
console.log("paymentRequest: " + JSON.stringify(error));
}
};

Keypress event not working on Android device

I have a directive which controls my input value desired formatted or not.
directive('validNumber', function(shareDataService)
{
return
{
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl)
{
if(!ngModelCtrl)
{
return;
}
ngModelCtrl.$parsers.push(function(val) {
if (angular.isUndefined(val)) {
var val = '';
}
var clean = val.replace(/[^-0-9\.]/g, '');
var decimalCheck = clean.split('.');
if(!angular.isUndefined(decimalCheck[1]))
{
decimalCheck[1] = decimalCheck[1].slice(0,2);
clean = decimalCheck[0] + '.' + decimalCheck[1];
}
if (val !== clean)
{
ngModelCtrl.$setViewValue(clean);
ngModelCtrl.$render();
}
return scope.hesapla(clean);
});
element.bind('keypress', function(event) {
if(event.keyCode === 32) { // space
event.preventDefault();
}
});
element.bind('keypress', function(event) {
if(event.keyCode === 45) { // - key
event.preventDefault();
}
});
}
};
})
It's working on browser perfectly but keypress event not working on the device.Tried to inspect device with google chrome but not firing. I also tried keyup or keydown but still not working. How can I get this done?
Thank you
Include jQuery Mobile file
What you need to do is just include a jQuery file into your project. A file named jQuery.mobile.js or quite similar (ex. jQuery.ui.js) of any version can help you.
You can download it from : Download | jQuery Mobile

Why the the httpInterceptor got rejected when the App starts even when there is network?

I'm using the following code to show a message when there is no network. It works well when testing the app in airplane mode. However, it always shows the popup even when there is network when the app code start (rejection.status === 0). How to workaround it?
.config(function($provide, $httpProvider) {
$provide.factory('httpInterceptor', function($q, $injector) {
return {
response: function(response) {
return response || $q.when(response);
},
responseError: function(rejection) {
var interactiveService = $injector.get('interactiveService');
if (rejection.status === 0 || rejection.status === -1) {
interactiveService.showPopup('The internet is disconnected on your device.' + rejection.status);
}
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('httpInterceptor');
})
If it helps try this
.config(function($provide, $httpProvider) {
$provide.factory('httpInterceptor', function($q, $injector) {
return {
response: function(response) {
return response || $q.when(response);
},
responseError: function(rejection) {
var interactiveService = $injector.get('interactiveService');
/************** New code starts*******/
var networkState = navigator.connection.type;
if(networkState === Connection.NONE){
interactiveService.showPopup('The internet is disconnected on your device.' + rejection.status);
}
/************** New code ends*******/
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('httpInterceptor');
})

How to listen Android hardware back button in ionic

I try to listen android hardware back button,but it is no effect.
main code:
.run(['$ionicPlatform','$ionicHistory',function($ionicPlatform,$ionicHistory) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
$ionicPlatform.registerBackButtonAction(function (e) {
e.preventDefault();
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$ionicHistory.viewHistory().backView.go();
return false;
}, 100);
}])
My running environment is mobile browser.Android version 4.4.2
UPDATE: I'm no longer using this as it was unreliable. Additionally, in the latest Ionic release, app.ts is now app.component.ts.
For Ionic 2, check out my blog post on how to fix this. Should also work for Ionic 1, as it's only calling a cordova listener:
http://www.codingandclimbing.co.uk/blog/ionic-2-android-back-button-13
and here's the actual post info:
In your app.ts, do the following to get the back button working as expected (mostly!):
initializeApp() {
this.platform.ready().then(() => {
this.registerBackButtonListener();
});
}
registerBackButtonListener() {
document.addEventListener('backbutton', () => {
var nav = this.getNav();
if (nav.canGoBack()) {
nav.pop();
}
else {
this.confirmExitApp(nav);
}
});
}
confirmExitApp(nav) {
let confirm = Alert.create({
title: 'Confirm Exit',
message: 'Really exit app?',
buttons: [
{
text: 'Cancel',
handler: () => {
console.log('Disagree clicked');
}
},
{
text: 'Exit',
handler: () => {
navigator.app.exitApp();
}
}
]
});
nav.present(confirm);
}
getNav() {
return this.app.getComponent('nav');
}
Note:
If you get errors about app not being a property of navigator:
1) Add a typings folder to your app root: e.g. app/typings
2) Add a file called: pluginshackyhacky.d.ts
3) Add for properties you need extended for TypeScript to compile.:
interface /*PhoneGapNavigator extends*/ Navigator {
app: any;
}
4) Add the pluginshackyhacky.d.ts to the compile in the tsconfig.json:
"files": [
"app/app.ts",
"app/typings/pluginshackyhacky.d.ts",
"app/typings/phonegap.d.ts"
]
You can see that I've also included the phonegap.d.ts file which includes a lot of missing properties/variables that allows TypeScript to compile without errors.
Hope this helps anyone having this problem.
Cheers.
may be this could help you.
$state.$current.name == "";var backbutton=0;
$ionicPlatform.registerBackButtonAction(function (event) {
if (($state.$current.name == "app.intro") ||
($state.$current.name == "app.main.home") ||
($state.$current.name == "app.account")) {
if(backbutton==0){
backbutton++;
window.plugins.toast.showLongBottom('Press again to exit');
$timeout(function(){backbutton=0;},3000);
}else{
navigator.app.exitApp();
}
console.log("one");
}else if($state.$current.name == "app.welcome.takeControl") {
console.log("two");
$state.go("app.main.home");
}else{
console.log("three");
navigator.app.backHistory();
}
}, 100);

Exit application from android hardware back button in phonegap

Is there a way to show a confirmation popup when you press the hardware back button in android devices to exit the phonegap/ionic application?
In the current status, my app keep going to the previous state upon clicking the back button.
Is there a way to exit the app when you press the back button no matter where you are on, in the application?
I found this piece of code but it did not seem to work:
$ionicPlatform.registerBackButtonAction(function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Sign Out Confirm',
template: 'Are you sure you want to Logout?'
});
confirmPopup.then(function(res) {
if (res) {
$rootScope.rootScopeUserTransactionPassword = null;
$state.go('app.playlists');
} else {
console.log('You are not sure');
}
});
}, 100);
Try this:
document.addEventListener('backbutton', function(event){
event.preventDefault(); // EDIT
navigator.app.exitApp(); // exit the app
});
I hope it helps you.
It will ask you before exit in stipulated timestamp : Press back button again to exit. If it's dashboard page then it will ask whether to Log out?
I hope it will solve your problem.
.run(function($rootScope, $ionicPlatform, $ionicHistory){
$ionicPlatform.registerBackButtonAction(function(e) {
if ($ionicHistory.currentView().stateName == 'dashboard') {
Dialogs.showConfirm('Do you want to logout?', function(buttonIndex) {
if (buttonIndex == 1)
User.clear();
}, 'Logout', ['Yes', 'No']);
} else
if ($rootScope.backButtonPressedOnceToExit) {
ionic.Platform.exitApp();
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
$rootScope.backButtonPressedOnceToExit = true;
window.plugins.toast.showShortCenter(
"Press back button again to exit",
function(a) {},
function(b) {}
);
setTimeout(function() {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000);
}
e.preventDefault();
return false;
}, 101);
});
The following close the app if we hit back button on Android device in "Login" screen.
In your app.js you maybe have something like this:
app.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
$stateProvider.state('login', {
url : '/',
}).state('login', {
url : '/login',
views : {
contentView : {
templateUrl : 'login.html',
controller : 'LoginCtrl'
}
}
});
So all you have to do is add this method in the same file:
app.run(function($ionicPlatform) {
$ionicPlatform.registerBackButtonAction(function() {
if ($state.current.name == "login") {
navigator.app.exitApp();
}
}, 100);
});
Note that "login" it the state name which mentioned in the app.config

Categories

Resources