Android 如何在活动OnEvent方法(深度链接)中重新路由Angularjs Nativescript应用程序

Android 如何在活动OnEvent方法(深度链接)中重新路由Angularjs Nativescript应用程序,android,angularjs,nativescript,deep-linking,Android,Angularjs,Nativescript,Deep Linking,我正在扩展Activity类,以便接收新的intent数据。这是预期的工作,但我无法找出如何根据我得到的数据路由我的应用程序 import { setActivityCallbacks, AndroidActivityCallbacks } from "ui/frame"; @JavaProxy("org.myApp.MainActivity") class Activity extends android.app.Activity { private _callbacks: Andr

我正在扩展Activity类,以便接收新的intent数据。这是预期的工作,但我无法找出如何根据我得到的数据路由我的应用程序

import { setActivityCallbacks, AndroidActivityCallbacks } from "ui/frame";

@JavaProxy("org.myApp.MainActivity")
class Activity extends android.app.Activity {
    private _callbacks: AndroidActivityCallbacks;

    protected onCreate(savedInstanceState: android.os.Bundle): void {
        if (!this._callbacks) {
            setActivityCallbacks(this);
        }

        this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
    }

    protected onNewIntent(intent: android.content.Intent): void {
      super.onNewIntent(intent)
      if (intent.getDataString) {
        let data = intent.getDataString();

        if (data) {
          console.log('onNewIntent data ', data);
          //How do I route my Angularjs Nativescript application here based on the data I get back?
        }
      }
    }
}

我的问题是这里的答案

但这是我要找的东西的片段

在activity.android.ts文件中,创建并发送意图数据的EventEmitter

import { EventEmitter } from '@angular/core';
import { setActivityCallbacks, AndroidActivityCallbacks } from "ui/frame";

export var OnRouteToURL = new EventEmitter<string>();

@JavaProxy("org.myApp.MainActivity")
class Activity extends android.app.Activity {
    private _callbacks: AndroidActivityCallbacks;

    protected onCreate(savedInstanceState: android.os.Bundle): void {
        if (!this._callbacks) {
            setActivityCallbacks(this);
        }

        this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
    }

    protected onNewIntent(intent: android.content.Intent): void {
        super.onNewIntent(intent);


        if (intent.getAction() === android.content.Intent.ACTION_VIEW){
            const dataStr = intent.getDataString();
            OnRouteToURL.next(dataStr);
        }
    }
}
从'@angular/core'导入{EventEmitter};
从“ui/frame”导入{setActivityCallbacks,AndroidActivityCallbacks};
导出var OnRouteToURL=new EventEmitter();
@JavaProxy(“org.myApp.MainActivity”)
类活动扩展了android.app.Activity{
私有回调:AndroidActivityCallbacks;
protectedoncreate(savedInstanceState:android.os.Bundle):void{
如果(!this.\u回调){
setActivityCallbacks(此);
}
this.\u callbacks.onCreate(this,savedInstanceState,super.onCreate);
}
受保护的onNewIntent(intent:android.content.intent):无效{
super.onNewIntent(意向);
if(intent.getAction()==android.content.intent.ACTION\u视图){
const dataStr=intent.getDataString();
OnRouteToURL.next(dataStr);
}
}
}
并在app.component.ts文件中导入OnRouteToURL eventEmitter并订阅它

import { Component, OnInit, EventEmitter, NgZone } from "@angular/core";
import { Router } from '@angular/router';
import * as application from 'application';
import { isAndroid, isIOS } from 'platform';

let OnRouteToURL: EventEmitter<string>;
if (isIOS) {
    application.ios.delegate = require('./delegate').CustomAppDelegate
    OnRouteToURL = require('./delegate').OnRouteToURL;
} else if (isAndroid) {
    OnRouteToURL = require('./activity').OnRouteToURL;
}

@Component({
    selector: "ns-app",
    templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {

    constructor(
        private zone: NgZone,
        private router: Router
    ) {
    }

    ngOnInit() {
        // Subscribe to routing events from both platforms
        OnRouteToURL.subscribe((url) => this.handleRouting(url));
    }

    handleRouting(url: string) {
        // Assume everything after :// is an app route
        // in production you might want to limit which routes are allowed to deep-link
        const route = url.substr(url.indexOf('://') + 3);
        console.log(`AppComponent: Navigate to route '${route}'`);

        // Do the routing in the Angular Zone, just to be sure
        this.zone.run(() => {
            this.router.navigateByUrl(route);
        });
    }
}
从“@angular/core”导入{Component,OnInit,EventEmitter,NgZone};
从'@angular/Router'导入{Router};
从“应用程序”导入*作为应用程序;
从“平台”导入{isAndroid,isIOS};
让OnRouteToURL:EventEmitter;
国际单项体育联合会(isIOS){
application.ios.delegate=需要('./delegate')。CustomAppDelegate
OnRouteToURL=需要('./委托')。OnRouteToURL;
}else if(isAndroid){
OnRouteToURL=需要('./活动')。OnRouteToURL;
}
@组成部分({
选择器:“ns应用程序”,
templateUrl:“app.component.html”,
})
导出类AppComponent实现OnInit{
建造师(
私人区域:NgZone,
专用路由器
) {
}
恩戈尼尼特(){
//从两个平台订阅路由事件
OnRouteToURL.subscribe((url)=>this.handleRouting(url));
}
HandlerRouting(url:string){
//假设://之后的所有内容都是应用程序路由
//在生产中,您可能希望限制允许深度链接的路由
const route=url.substr(url.indexOf('://')+3);
log(`AppComponent:Navigate to route'${route}`);
//在角度区域进行布线,以确保
此.zone.run(()=>{
这个.router.navigateByUrl(路由);
});
}
}

我的问题是这里的答案

但这是我要找的东西的片段

在activity.android.ts文件中,创建并发送意图数据的EventEmitter

import { EventEmitter } from '@angular/core';
import { setActivityCallbacks, AndroidActivityCallbacks } from "ui/frame";

export var OnRouteToURL = new EventEmitter<string>();

@JavaProxy("org.myApp.MainActivity")
class Activity extends android.app.Activity {
    private _callbacks: AndroidActivityCallbacks;

    protected onCreate(savedInstanceState: android.os.Bundle): void {
        if (!this._callbacks) {
            setActivityCallbacks(this);
        }

        this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
    }

    protected onNewIntent(intent: android.content.Intent): void {
        super.onNewIntent(intent);


        if (intent.getAction() === android.content.Intent.ACTION_VIEW){
            const dataStr = intent.getDataString();
            OnRouteToURL.next(dataStr);
        }
    }
}
从'@angular/core'导入{EventEmitter};
从“ui/frame”导入{setActivityCallbacks,AndroidActivityCallbacks};
导出var OnRouteToURL=new EventEmitter();
@JavaProxy(“org.myApp.MainActivity”)
类活动扩展了android.app.Activity{
私有回调:AndroidActivityCallbacks;
protectedoncreate(savedInstanceState:android.os.Bundle):void{
如果(!this.\u回调){
setActivityCallbacks(此);
}
this.\u callbacks.onCreate(this,savedInstanceState,super.onCreate);
}
受保护的onNewIntent(intent:android.content.intent):无效{
super.onNewIntent(意向);
if(intent.getAction()==android.content.intent.ACTION\u视图){
const dataStr=intent.getDataString();
OnRouteToURL.next(dataStr);
}
}
}
并在app.component.ts文件中导入OnRouteToURL eventEmitter并订阅它

import { Component, OnInit, EventEmitter, NgZone } from "@angular/core";
import { Router } from '@angular/router';
import * as application from 'application';
import { isAndroid, isIOS } from 'platform';

let OnRouteToURL: EventEmitter<string>;
if (isIOS) {
    application.ios.delegate = require('./delegate').CustomAppDelegate
    OnRouteToURL = require('./delegate').OnRouteToURL;
} else if (isAndroid) {
    OnRouteToURL = require('./activity').OnRouteToURL;
}

@Component({
    selector: "ns-app",
    templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {

    constructor(
        private zone: NgZone,
        private router: Router
    ) {
    }

    ngOnInit() {
        // Subscribe to routing events from both platforms
        OnRouteToURL.subscribe((url) => this.handleRouting(url));
    }

    handleRouting(url: string) {
        // Assume everything after :// is an app route
        // in production you might want to limit which routes are allowed to deep-link
        const route = url.substr(url.indexOf('://') + 3);
        console.log(`AppComponent: Navigate to route '${route}'`);

        // Do the routing in the Angular Zone, just to be sure
        this.zone.run(() => {
            this.router.navigateByUrl(route);
        });
    }
}
从“@angular/core”导入{Component,OnInit,EventEmitter,NgZone};
从'@angular/Router'导入{Router};
从“应用程序”导入*作为应用程序;
从“平台”导入{isAndroid,isIOS};
让OnRouteToURL:EventEmitter;
国际单项体育联合会(isIOS){
application.ios.delegate=需要('./delegate')。CustomAppDelegate
OnRouteToURL=需要('./委托')。OnRouteToURL;
}else if(isAndroid){
OnRouteToURL=需要('./活动')。OnRouteToURL;
}
@组成部分({
选择器:“ns应用程序”,
templateUrl:“app.component.html”,
})
导出类AppComponent实现OnInit{
建造师(
私人区域:NgZone,
专用路由器
) {
}
恩戈尼尼特(){
//从两个平台订阅路由事件
OnRouteToURL.subscribe((url)=>this.handleRouting(url));
}
HandlerRouting(url:string){
//假设://之后的所有内容都是应用程序路由
//在生产中,您可能希望限制允许深度链接的路由
const route=url.substr(url.indexOf('://')+3);
log(`AppComponent:Navigate to route'${route}`);
//在角度区域进行布线,以确保
此.zone.run(()=>{
这个.router.navigateByUrl(路由);
});
}
}

Oh EventEmitter执行此操作,而不是ReplaySubject。。你救了我的命,伙计!!谢谢..哦EventEmitter做了这个把戏而不是ReplaySubject。。你救了我的命,伙计!!谢谢