I am new in titanium alloy development project, we already have an android app which was built on titanium template. I would like change this to alloy template.
My current issue is I need to make a user authentication. In our default app we use the following code
var xhr=Titanium.Network.createHTTPClient();
xhr.onerror = function(e){
Ti.API.error('Bad Sever =>'+e.error);
};
xhr.open("POST","http://xxxxxxxxx.com/api/login/");//ADD your URL
xhr.setRequestHeader("Set-Cookie", "application/json");
var param={ "username":$.email.value,"password":$.password.value,"api":true,"type":'P' };
Ti.API.info('Params'+JSON.stringify(param));
xhr.send(param);
Can I do same method in alloy app as well? Or have any other good methods?
If I use the same method I will get JSON response from API. Once logged in I would like to switch to new window.
Here I am using the code below to create new window.
var newwindow = Alloy.createController('threadShow');
newwindow.getView().open();
Is it right method? Or do have any other methods? How can I check whether user is authenticated or not in all controller? Or do we have any method like session as in web development project?
Yes that's ok, at the end of the day, Alloy is built on top of traditional Titanium and is not intending to replace it, just use commonJS and other best practices and you'll be fine
Related
Good afternoon,
I am trying to automate the following scenario on Android using Kotlin:
Start Appium driver and open React native app (driver1)
Perform some actions on React native app
Create driver2 with chrome options to open chrome and paste deep link there
Deeplink leads to the app automatically (but I suppose the current session uses driver2, not driver1 here)
I need to continue using the app further with driver1 however it is not working and not finding the element which is on the next screen where my deep link leaded me
I am using Appium v1,21,0
Language - Kotlin
App - React-native
I tried the following solutions:
getContext - does not work as this is not a hybrid app but two different mobile apps
startActivity - it actually launching the app from scratch, not continuing (i need to be on a particular screen after deep-link navigation, can't navigate anywhere else flow won't work)
startActivityCommand - this one did not work for me at all (it ignores the command but maybe anyone can give an example of its usage as I might use it wrong)
driver.switchTo().window("0") - did not work
assign to driver2(web) new capabilities - does not work as it is already defined so we cant change it
sessionId - I am not sure how it works exactly yet, but I tried to find a way to assign a driver to the particular session-id and was not successful (looks like AppiumDriver methods do not support it)
Would appreciate any ideas, links, or sources that can help archive the above
Good Day!
Solution that helped:
#AndroidFindBy(xpath = "//android.widget.EditText[#resource-id=\"com.android.chrome:id/search_box_text\"]")
#iOSXCUITFindBy(id = "")
lateinit var chromeURL: MobileElement
var deeplink = <your deeplink>
driver.activateApp("com.android.chrome")
chromeURL.sendKeys(deepLink)
var clickOnDeepLink = driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().text(\"$deepLink\")"))
clickOnDeepLink[0].click() //here we could not use Keys.ENTER so we just click on the element first in the list - default android google chrome behaviour
So there is no need for several drivers - same driver instance is fine
I have a Worklight 6.2 app. I am modifying the android java code to subscribe to a notification sent via Bluemix. After the user logs in, I would like to register the device using the userid that gets created. Is there an API call that I can use within the android code that is the equivalent to WL.Client.getUserName, or should I be calling the java code from my javascript and passing the userName to the java code? Thanks for any suggestions.
JT
There is no Java equivalent to this. This is a Worklight API.
What you can do is use the new WL.App.sendActionToNative method in Worklight 6.2 for to send a value to your native code and from there do what you need with it.
WL.App.sendActionToNative(“doSomething”, { customData: 12345} );
Where customdData is the WL.Client.getUserName.
On the native side you then need to use WLActionReciever (see What's New).
You could also opt to implement a basic Cordova plug-in that will move data from the web to native view.
The tutorial in the Getting Started page is doing exactly that.
I have a phonegap built android app made of html5 and javascript, i want to launch instagram app onclcik of a button.How is it possible without writing code in java?
There is a plugin for that. Check out this link: https://github.com/dmedvinsky/cordova-startapp.
Add it to your project, then simply call
window.startapp.start(
{
android: com.instagram.android',
ios: 'instagramURL'
},
successCallback, failureCallback
);
(you need to change the ios-url and the callbacks)
So I have been trying to run the Facebook Connect example for PhoneGap / Android with no luck.
https://github.com/davejohnson/phonegap-plugin-facebook-connect *
There are some similar threads with the same problem.. conclusion is that "Facebook SDK is a moving point"
I have succesfully compiled previously apps using phoneGap & Eclipse.
Now following the example* for Android. If I do exactly what they suggest. App shows the buttons but nothing happens when I click on them.
After analyzing the code I have noticed that
function initFB(){
try {
FB.init({ appId: "45253452345234523", nativeInterface: PG.FB });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}
there is a parameter nativeInterface : PG.FB which is nowhere described within Facebook API for this call..
http://developers.facebook.com/docs/reference/javascript/FB.init/
what is more interesting is that when i remove this parameter.. suddenly Login button goes to Facebook page with Error Code API 191.
So my question is what this parameter is supposed to do? and why it is not in Facebook API?
I have found no info about this parameter in internet. I guess if it would be a case of an out-dated FB API there would be some info available.
Any ideas?
Thanks,
Marcin
The "nativeInterface: PG.FB" option is to tell PhoneGap to use the native authentication interface instead of the mobile web interface. If you don't add in the "PG.FB" option, you'll get redirected to Facebook's mobile authentication instead. It took me a while to figure this out too, and it's not well documented, but that's what is going on.
Two other things about the PhoneGap Facebook Plugin that are not up to date with the latest Facebook JavaScript SDK:
When using FB.login() you should be using the "scope" parameter, but PhoneGap expects the deprecated "perms" parameter.
When the authentication response from FB.login() you should be getting "response.authResponse", but instead "response.session" is what is given back. This means you'll have to pull out the OAuth Access token with "response.session.auth_token" instead of "response.authResponse.accessToken".
Hopefully they'll get to updating the PhoneGap Facebook Plugin, but for now I use if/else statements to detect if PhoneGap is there. You can check if PhoneGap is initialized by using:
if(window.PhoneGap) {
//PhoneGap Library is Loaded
}
I am using titanium to develop android application.
In my application i have to make call from the application.
I am writing Java Script to develop application.
So My question is is there any way by which i can make call from my application when i am using titanium,as we can do in native android code by calling Intent to call to specific number.
Thanks,
Rakesh
Yes you can make call like this:
Ti.Platform.openURL('tel://911');
Or For Prompt,
Ti.Platform.openURL('telprompt://911');
For more details Titanium Platform
I found this, maybe it's the way on android:
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_CALL,
data: 'tel:12421342'
});
Ti.Android.currentActivity.startActivity(intent);
I've not tried it yet. Good luck!
(Aase