I have this simple gui script that opens a url when clicked. I dont need to actually open the url in browser, because it is just an adress to a php file. The code works fine when I tried in PC, but nothing happened when I run it on Android device.
Here is the code:
#pragma strict
var one = "192.168.0.125:8888/one";
var two = "192.168.0.125:8888/two";
Var three = "192.168.0.125:8888/three";
Var all = "192.168.0.125:8888/all";
function Start () {
}
function Update () {
Screen.orientation = ScreenOrientation.Portrait;
}
function OnGUI () {
if (GUI.Button (Rect (20,20,300, 75), "ONE")) {
var ONE_ : WWW = new WWW(one);
}
else if(GUI.Button (Rect(20,200,300, 75), "TWO")){
var TWO_ : WWW = new WWW(two);
}
else if(GUI.Button (Rect(20,380,300, 75), "THREE")){
var THREE_ : WWW = new WWW(three);
}
else if(GUI.Button (Rect(20,560,300, 75), "ALL")){
var ALL_ : WWW = new WWW(all);
}
}
Any Ideas? Thanks
You are not waiting for the WWW class to finish the request.
You need to declare the WWW class in a different method (or make it a class var) and use the yield syntax to wait for it.
Your code should look something like this:
#pragma strict
var one = "192.168.0.125:8888/one";
var two = "192.168.0.125:8888/two";
var three = "192.168.0.125:8888/three";
var all = "192.168.0.125:8888/all";
function Start () {
}
function Update () {
Screen.orientation = ScreenOrientation.Portrait;
}
function CreateWWW(address)
{
var wwwAccess : WWW = new WWW(address);
yield wwwAccess;
}
function OnGUI () {
if (GUI.Button (Rect (20,20,300, 75), "ONE")) {
CreateWWW(one);
}
else if(GUI.Button (Rect(20,200,300, 75), "TWO")){
CreateWWW(two);
}
else if(GUI.Button (Rect(20,380,300, 75), "THREE")){
CreateWWW(three);
}
else if(GUI.Button (Rect(20,560,300, 75), "ALL")){
CreateWWW(all);
}
}
Here's the link to the Unity docs
Also, you don't need to specify the orientation on each update, you can set it from PlayerSettings->Resolution and Presentation->Allowed orientations for Auto Rotation.
Related
I am trying to get payment from my application. Everything is working fine on iOS. But on Android, my function stuck on this line:
Stripe.publishableKey = pk_key;
await Stripe.instance.applySettings(); // after this line nothings happens.
thanks in advance.
Here is my full code:
try{
Stripe.publishableKey = pk_key;
await Stripe.instance.applySettings();
var total = cartInfo.getTotal();
var customerEmail = cartInfo.address!.email;
var data = {
'email': customerEmail,
'amount': (total*100),
};
var payment_intent = await postRequest(url, data);
// widget.onLoading!(false);
print(payment_intent);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: payment_intent['paymentIntent'],
merchantDisplayName: 'test',
customerId: payment_intent['customer'],
customerEphemeralKeySecret: payment_intent['ephemeralKey'],
merchantCountryCode: 'UAE',
)
);
setState((){});
await Stripe.instance.presentPaymentSheet();
return true;
} catch(e) {
return false;
}
EDIT:
I updated FlutterActivity to FlutterFragmentActivity in main kotlin file. But now undefined method: cotext error raised. I dont understant why? here is the full kotlin code.
https://pastecode.io/s/z86216b1
I am working on a ionic project and trying to use LokiJS. Below is my code,
controller,
$scope.test ={birthdays:[]};
$ionicPlatform.ready(function() {
BirthdayService.initDB();
BirthdayService.getAllBirthdays().then(function(birthdays){
console.log("birthdays=",birthdays);// gives empty array second run...
//var bday1 = {Name:"abrj",Date:new Date()};
//var bday2 = {Name:"abrj2",Date:new Date()};
//BirthdayService.addBirthday(bday1);
//BirthdayService.addBirthday(bday2); added birthdays during the first run.
});
});
I am using cordova-fs-adapter and cordova-file-plugin.
below is my service for adapter integration,
(function() {
angular.module('starter').factory('BirthdayService', ['$q', 'Loki', BirthdayService]);
function BirthdayService($q, Loki) {
var _db;
var _birthdays;
function initDB() {
var fsAdapter = new LokiCordovaFSAdapter({"prefix": "loki"});
_db = new Loki('birthdaysDB',
{
autosave: true,
autosaveInterval: 1000, // 1 second
adapter: fsAdapter
});
};
function getAllBirthdays() {
return $q(function (resolve, reject) {
var options = {
birthdays: {
proto: Object,
inflate: function (src, dst) {
var prop;
for (prop in src) {
if (prop === 'Date') {
dst.Date = new Date(src.Date);
} else {
dst[prop] = src[prop];
}
}
}
}
};
_db.loadDatabase(options, function () {
_birthdays = _db.getCollection('birthdays');
if (!_birthdays) {
_birthdays = _db.addCollection('birthdays');
}
resolve(_birthdays.data);
});
});
};
function addBirthday(birthday) {
console.log("Birthdays=",_birthdays);
_birthdays.insert(birthday);
};
function updateBirthday(birthday) {
_birthdays.update(birthday);
};
function deleteBirthday(birthday) {
_birthdays.remove(birthday);
};
return {
initDB: initDB,
getAllBirthdays: getAllBirthdays,
addBirthday: addBirthday,
updateBirthday: updateBirthday,
deleteBirthday: deleteBirthday
};
}
})();
In first run I am inserting two documents into the birthdays collections.On second run when I trying to check whether they have persisted, they weren't. I know I am doing something wrong.Do suggest.Local storage also gets cleared everytime i rerun(ionic run android)?!
I am developing a custom Cordova plugin. For some reason, I am restricted to expose all my JS objects through single JavaScript file only. Below sample JS replicating my Problem
My JS have 2 objects apple and orange, I have to export them from single file
var apple = function() {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
};
var orange = function() {
color: "red2",
show: function () {
alert("test type 2 also passed dude !----");;
}
};
I am exporting them like this
var apple1 = new apple();
module.exports = apple1;
var orange1 = new orange();
module.exports = orange1;
My problem is orange1 is overriding apple1 export. How to export both apple1 and orange1 using module.exports? or there any other way?
Please provide me some inputs. Any samples are most welcome.
Following approach worked for me.
var apple1 = new apple();
var orange1 = new orange();
var myExports = module.exports;
myExports .apple1 = apple1;
myExports .orange1 = orange1;
i've got an error, and only on android:
i have a code like this:
var selfWin;
var blackScreen;
var actInd;
var Login = require('ui/common/Login');
var myLogin;
var HomeView = require('ui/common/Home');
var homeView;
function ApplicationWindow() {
var selfWin = Ti.UI.createWindow({
backgroundColor:'#ffffff',
navBarHidden:true,
exitOnClose:true
});
blackScreen = Ti.UI.createLabel({
backgroundColor:'#000000',
opacity:0.40,
top:0,
height:'100%',
width:'100%',
zIndex:100
});
actInd = Ti.UI.createActivityIndicator({
width:50,
height:50,
zIndex:101
});
selfWin.add(blackScreen);
selfWin.add(actInd);
Ti.App.HideBlackScreen();
Ti.App.GoToFirstView();
return selfWin;
}
Ti.App.ShowBlackScreen = function ShowBlackScreen() {
blackScreen.show();
actInd.show();
};
Ti.App.HideBlackScreen = function HideBlackScreen() {
blackScreen.hide();
actInd.hide();
};
Ti.App.GoToFirstView = function GoToFirstView() {
myLogin = new Login();
selfWin.add(myLogin);
if (homeView) {
selfWin.remove(homeView);
}
};
Ti.App.GoToHome = function GoToHome() {
homeView = new HomeView();
selfWin.add(homeView);
selfWin.remove(myLogin);
};
//make constructor function the public component interface
module.exports = ApplicationWindow;
and this error occoured at selfWin.add(myLogin); inside the GoToFirstView() function, and only on android.
someone can help me?
Thanks a lot
try to make your selfWin object global like below.Because it is private variable which is not exist out side that Application function(). There are two way to achieve this.
1.
var selfWin;
function ApplicationWindow() {
selfWin = Ti.UI.createWindow({
backgroundColor : '#ffffff',
navBarHidden : true,
exitOnClose : true
});
}
2.Pass your window object with your function like below.
Ti.App.GoToFirstView(selfWin);
Ti.App.GoToFirstView = function GoToFirstView(selfWin) {
myLogin = new Login();
selfWin.add(myLogin);
if (homeView) {
selfWin.remove(homeView);
}
};
Best Regards,
Nitin Chavda
I want to traverse through each file in the SD card inside all the directories and sub directories using the FILE API of phonegap (which is the w3c file api actually). I have to perform a certain set of operations on these files by looking at their nature. I donot want to search for specific types of files, but traverse through each file in a sequential manner.
Can someone please help me with this? Just a basic loop framework with the necessary requirements for the traversal would be a great help.
Thank You in advance.
I think the following code should work:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onRequestFileSystem, fail);
function onRequestFileSystem(fileSystem) {
var directoryReader = fileSystem.root.createReader();
directoryReader.readEntries(onReadEntries, fail);
}
function onReadEntries(entries) {
var i;
for (i = 0; i < entries.length; i++) {
if (entries[i].isFile == true) {
// ...
}
if (entries[i].isDirectory == true) {
var directoryReader = entries[i].fullPath.createReader();
directoryReader.readEntries(onReadEntries, fail);
}
}
}
http://www.c-sharpcorner.com/UploadFile/e83792/filesystem-directoryentry-objects-in-phonegap/
scan : function(url,fileType,callback)
{
var fileTypeCollection = [];
var defer = $q.defer();
url.forEach(function(element, index)
{
//requestLocalFileSystemURL
log(element);
window.resolveLocalFileSystemURL(element,onRequestFileSystem, fail);
log("Ends resolve");
});
function onRequestFileSystem(fileSystem)
{
var directoryReader = fileSystem.createReader();
directoryReader.readEntries(onReadEntries,fail);
} /*onRequestFile Ends*/
function onReadEntries(entries)
{
if(entries.length==0)
{
log("Entries Length....Resolving");
defer.resolve(fileTypeCollection);
}
else
{
entries.forEach( function(element, index)
{
if (element.isDirectory === true)
{
// Recursive -- call back into this subdirectory
onRequestFileSystem(element);
}
if(element.isFile == true)
{
fileType.forEach(function(type)
{
if(element.name.indexOf(type) != -1)
{
fileTypeCollection.push(element);
}
});
} /*is File ENds*/
}); /*Entries For Each Ends*/
}
} /*OnRead Ends*/
function fail(resp)
{
log(resp);
defer.reject();
} /*Fail Ends*/
return defer.promise;
} //Scan Function Ends
try this. remove the promises if u wish and use a callback.promises is kind of broken. if you can fix then its ok else use a callback after push for FileType