Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add callback support to Ti.Platform.openURL() #11668

Merged
merged 3 commits into from May 13, 2020

Conversation

jquick-axway
Copy link
Contributor

@jquick-axway jquick-axway commented Apr 29, 2020

JIRA:
https://jira.appcelerator.org/browse/TIMOB-27862

Note:
The following mocha suite PR will unit test this via app custom URL scheme.
https://github.com/appcelerator/titanium-mobile-mocha-suite/pull/250

Test:

  1. Build and run the below code on Android.
  2. Tap on the "OpenURL(url)" button.
  3. Verify it launches a web browser showing Google's website.
  4. Verify the log shows the below:
    @@@ openURL() returned: true
  5. Navigate back to the Titanium app.
  6. Tap on the "OpenURL(url, callback)" button.
  7. Verify it launches a web browser showing Google's website.
  8. Verify the log shows the below. Event must be logged last with success set to true:
    @@@ openURL() returned: true
    @@@ openURL() event: {"code":0,"success":true}
  9. Navigate back to the Titanium app.
  10. Tap on the "OpenURL(url, options, callback)" button.
  11. Verify it launches a web browser showing Google's website.
  12. Verify the log shows the below. Event must be logged last with success set to true:
    @@@ openURL() returned: true
    @@@ openURL() event: {"code":0,"success":true}
  13. Navigate back to the Titanium app.
  14. Tap on the "OpenURL(bad-url)" button.
  15. Verify that nothing launches. (This is good. It has a bad URL.)
  16. Verify the log shows the below. Returned value must be false.
    @@@ openURL() returned: false
  17. Tap on the "OpenURL(bad-url)" button.
  18. Verify that nothing launches. (This is good. It has a bad URL.)
  19. Verify the log shows the below. Event must be logged last and success set to false:
    [INFO] @@@ openURL() returned: false
    [INFO] @@@ openURL() event: {"code":1,"success":false}
var url = "https://www.google.com";
var badUrl = "idontexist://";

var window = Ti.UI.createWindow({
	layout: "vertical",
});
var open1Button = Ti.UI.createButton({
	title: "openURL(url)",
	top: Ti.App.iOS ? "40dp" : "20dp",
});
open1Button.addEventListener("click", function() {
	var result = Ti.Platform.openURL(url);
	Ti.API.info("@@@ openURL() returned: " + result);
});
window.add(open1Button);
var open2Button = Ti.UI.createButton({
	title: "openURL(url, callback)",
	top: "20dp",
});
open2Button.addEventListener("click", function() {
	var result = Ti.Platform.openURL(url, function(e) {
		Ti.API.info("@@@ openURL() event: " + JSON.stringify(e));
	});
	Ti.API.info("@@@ openURL() returned: " + result);
});
window.add(open2Button);
var open3Button = Ti.UI.createButton({
	title: "openURL(url, options, callback)",
	top: "20dp",
});
open3Button.addEventListener("click", function() {
	var openOptions = {
		UIApplicationOpenURLOptionsOpenInPlaceKey: true,
	};
	var result = Ti.Platform.openURL(url, openOptions, function(e) {
		Ti.API.info("@@@ openURL() event: " + JSON.stringify(e));
	});
	Ti.API.info("@@@ openURL() returned: " + result);
});
window.add(open3Button);
var open4Button = Ti.UI.createButton({
	title: "openURL(bad-url)",
	top: "20dp",
});
open4Button.addEventListener("click", function() {
	var result = Ti.Platform.openURL(badUrl);
	Ti.API.info("@@@ openURL() returned: " + result);
});
window.add(open4Button);
var open5Button = Ti.UI.createButton({
	title: "openURL(bad-url, callback)",
	top: "20dp",
});
open5Button.addEventListener("click", function() {
	var result = Ti.Platform.openURL(badUrl, function(e) {
		Ti.API.info("@@@ openURL() event: " + JSON.stringify(e));
	});
	Ti.API.info("@@@ openURL() returned: " + result);
});
window.add(open5Button);
window.open();

@build
Copy link
Contributor

build commented Apr 29, 2020

Messages
📖

💾 Here's the generated SDK zipfile.

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖

✅ All tests are passing
Nice one! All 6567 tests are passing.
(There are 709 skipped tests not included in that total)

Generated by 🚫 dangerJS against 16f2b5b

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

@ssekhri
Copy link

ssekhri commented May 13, 2020

FR Passed.

Verified on:
Mac OS: 10.15.4
SDK: 9.1.0.v20200325104908
Appc CLI: 8.0.0
JDK: 11.0.4
Node: 10.16.3
Studio: 9.1.0.v20200430104404
Device: Nexus4(v5.1.1) device, Pixel3(v10.0) emulator

@ssekhri ssekhri merged commit 43d287e into tidev:master May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants