方式一,无需回调结果:

let platform = uni.getSystemInfoSync().platform;
if (platform == 'android') {

	//获取宿主上下文
	var main = plus.android.runtimeMainActivity();

	var openUrl = "sway://openapi:8848/oauthLogin?appKey=" + this.appKey + "&pkgName=" + this
		.pkgName;
	console.log(openUrl);

	//通过反射获取Android的Uri对象
	var Uri = plus.android.importClass("android.net.Uri");
	var uri = Uri.parse(openUrl);

	//通过反射获取Android的Intent对象
	var Intent = plus.android.importClass("android.content.Intent");
	var intent = plus.android.newObject("android.content.Intent", Intent.ACTION_VIEW, uri);

	main.startActivity(intent);

} else {
	uni.showToast({
		title: "仅支持安卓客户端",
		icon: 'none',
		duration: 2000
	});
}

 

方式二,需要回调结果:

let platform = uni.getSystemInfoSync().platform;
if (platform == 'android') {

	//获取宿主上下文
	var main = plus.android.runtimeMainActivity();

	var openUrl = "sway://openapi:8848/oauthLogin?appKey=" + this.appKey + "&pkgName=" + this
		.pkgName;
	console.log(openUrl);

	//通过反射获取Android的Uri对象
	var Uri = plus.android.importClass("android.net.Uri");
	var uri = Uri.parse(openUrl);

	//通过反射获取Android的Intent对象
	var Intent = plus.android.importClass("android.content.Intent");
	var intent = plus.android.newObject("android.content.Intent", Intent.ACTION_VIEW, uri);

	//请求码保证了,开始的新界面和返回的是同一个操作
	var CODE_REQUEST = 1000

	main.startActivityForResult(intent, CODE_REQUEST);

	//设置原生界面返回后的回调操作
	main.onActivityResult = function(requestCode, resultCode, data) {
		if (requestCode == CODE_REQUEST) {
			//alert(requestCode); //这个是正确的 1000  
			//alert(resultCode); //始终都是0  
			//alert(data); //弹出 undefined
			plus.android.importClass(data);
			var bundle = data.getExtras();
			plus.android.importClass(bundle);
			let result = eval('(' + bundle.getString("data") + ')');
		}
	}
} else {
	uni.showToast({
		title: "仅支持安卓客户端",
		icon: 'none',
		duration: 2000
	});
}