【问题标题】:Titanium - Android: Intent - getData(), getAction() always equal to nullTitanium - Android:Intent - getData()、getAction() 始终等于 null
【发布时间】:2018-03-16 08:01:59
【问题描述】:

当我为我的项目使用深层链接并尝试访问Ti.Android.currentActivity.getIntent().getData() 时,它总是为Ti SDK 6.2.0 及更高版本返回null,但如果我将SDK 降级到6.1.2,那么它可以正常工作。它无法从传入的意图中读取数据。

复制步骤:

  1. 新建合金App,使用如下测试代码
  2. 在任何安卓设备上安装应用程序。
  3. 转到浏览器并浏览到链接app name://videoURL
  4. 它将打开应用程序,但getData() 始终为空,但它应该返回一个 URL

预期结果:当应用程序从深层链接打开时,它应该返回 URL。

这里是测试代码:

在alloy.js 中:

Alloy.Globals.getDeepLinkURL = function() {
    Alloy.Globals.deepLinkURLAndroid =Ti.Android.currentActivity.getIntent().getData();

    console.log("Alloy.Globals.deepLinkURLAndroid");
    console.log(Alloy.Globals.deepLinkURLAndroid);
    console.log(Ti.Android.currentActivity.getIntent());
};

在 index.js 中:

$.index.addEventListener('open',function(){
    if(OS_ANDROID){
        Alloy.Globals.getDeepLinkURL();
    }

});

【问题讨论】:

  • 您好像忘记添加要重现的测试代码了。
  • 嗨,哈姆,感谢您的回复。我已经添加了测试代码。

标签: javascript android titanium-mobile deep-linking appcelerator-titanium


【解决方案1】:
Ti.Android.currentActivity.addEventListener('newintent', function (e) {
    var data = e.intent.getData();
    alert(`data: ${data}`);
});

返回数据但此代码仅适用于 index.js 文件

【讨论】:

    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多