Skip to content

Instantly share code, notes, and snippets.

@RoyiNamir
Last active July 4, 2018 13:14
Show Gist options
  • Save RoyiNamir/0b503d69448e1e6cb0fa74f3f2481d62 to your computer and use it in GitHub Desktop.
Save RoyiNamir/0b503d69448e1e6cb0fa74f3f2481d62 to your computer and use it in GitHub Desktop.
import {ReplaySubject} from "rxjs";
import {AndroidActivityCallbacks, setActivityCallbacks} from "ui/frame";
export let AndroidOnRouteToURL = new ReplaySubject<string>();
@JavaProxy("org.myApp.MainActivity")
export class ActivityAndroid extends android.support.v7.app.AppCompatActivity
{
private _callbacks: AndroidActivityCallbacks;
public onBackPressed(): void
{
this._callbacks.onBackPressed(this, super.onBackPressed);
}
public onRequestPermissionsResult(requestCode: number, permissions: Array<String>, grantResults: Array<number>): void
{
this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined);
}
protected onCreate(savedInstanceState: android.os.Bundle): void
{
if (!this._callbacks)
{
setActivityCallbacks(this);
}
this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
const creationIntent = this.getIntent();
this.handleIntent(creationIntent);
}
protected onSaveInstanceState(outState: android.os.Bundle): void
{
this._callbacks.onSaveInstanceState(this, outState, super.onSaveInstanceState);
}
protected onStart(): void
{
this._callbacks.onStart(this, super.onStart);
}
protected onStop(): void
{
this._callbacks.onStop(this, super.onStop);
}
protected onDestroy(): void
{
this._callbacks.onDestroy(this, super.onDestroy);
}
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void
{
this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
}
protected onNewIntent(intent: android.content.Intent): void
{
super.onNewIntent(intent);
// console.info('MainActivity.onNewIntent');
this.handleIntent(intent);
}
private handleIntent(intent: android.content.Intent)
{
const action = intent.getAction();
const dataStr = intent.getDataString();
// console.info(`MainActivity.handleIntent: [${action}] ${dataStr}`);
if (action === android.content.Intent.ACTION_VIEW && dataStr !== null)
{
AndroidOnRouteToURL.next(dataStr);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment