从电子邮件中的链接打开Nativescript Android应用程序

时间:2016-07-18 20:51:38

标签: javascript android nativescript

我想从电子邮件中的链接打开我的Android应用程序。通过Stackoverflow搜索,看起来这可以使用指向我控制的URL的''来实现。虽然在使用Nativescript构建的Android应用程序的情况下,我有点困惑如何使用它。只是添加一个我拥有的特定数据路径的URL是唯一需要做的事情吗?在这种情况下会打开一个应用程序选择器对话框。以这种方式打开应用程序时,是否可以触发某个事件?谢谢您的帮助。下面是我需要做的样本。

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER" />

        <!-- Custom Path data -->
        <data
            android:host="www.some.company.com"
            android:path="/something"
            android:scheme="http"/>
    </intent-filter>

1 个答案:

答案 0 :(得分:3)

将此添加给您main.ts

import app = require("application");
import platform = require("platform");

declare var android: any;

if(!!app.android){
    app.android.on(app.AndroidApplication.activityResumedEvent, function (args) { 
        console.log("Event: " + args.eventName + ", Activity: " + args.activity); 
        console.log(new String(args.activity.getIntent().getAction()).valueOf(), new String(android.content.Intent.ACTION_VIEW).valueOf());
        if(new String(args.activity.getIntent().getAction()).valueOf() ==  new String(android.content.Intent.ACTION_VIEW).valueOf()){
            console.log(args.activity.getIntent().getData()); 
        }
    });
}
相关问题