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

Sta*_*s_S 5 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>
Run Code Online (Sandbox Code Playgroud)

小智 5

添加这个给你 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()); 
        }
    });
}
Run Code Online (Sandbox Code Playgroud)