我正试图将用户引导到游戏商店。
import app = require("application");
var intent = new android.content.Intent("android.intent.action.VIEW" );
intent.setData( "market://details?id=MY.APP.LINK" );
app.android.currentContext.startActivity(intent);
以上不起作用!
我认为问题与我从Java代码转换为{N}可以使用的东西有关。
答案 0 :(得分:0)
以下是我使用TypeScript的代码。
import * as application from "application";
import * as Utility from "utils/utils";
declare var android: any;
gotoPlayStore() {
let androidPackageName = application.android.packageName;
let uri = android.net.Uri.parse("market://details?id=" + androidPackageName);
let myAppLinkToMarket = new android.content.Intent(android.content.Intent.ACTION_VIEW, uri);
// Launch the PlayStore
application.android.foregroundActivity.startActivity(myAppLinkToMarket);
}
gotoAppStore() {
let appStore = "";
appStore = "itms-apps://itunes.apple.com/en/app/id" + myAppId;
Utility.openUrl(appStore);
}
此代码基于Nic Raboy的插件
nativescript-rating
和此特定文件:https://github.com/nraboy/nativescript-ratings/blob/master/ratings.ts您可能会在Android上遇到此错误:错误错误:android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.VIEW dat = market:// details?id = your .package.id} ,但它正在真实设备上运行,因为Play Store应用程序正在其上运行。
答案 1 :(得分:0)
这对我有用:
try
{
let uri = android.net.Uri.parse( "market://details?id=com.company" );
var intent = new android.content.Intent( android.content.Intent.ACTION_VIEW, uri );
application.android.foregroundActivity.startActivity( intent );
}
catch ( e2 )
{
console.error( "Error =" + e2.message + "=" );
}