递归火山软件开发平台
标题:
java这段用火山应该怎么写
[打印本页]
作者:
萧萧
时间:
3 天前
标题:
java这段用火山应该怎么写
本帖最后由 萧萧 于 2025-9-10 13:52 编辑
/**
* 启动游戏并传递授权code
*
* @param code 授权获取的code
*/
private void launchGameWithCode(String code) {
// 校验code合法性
if (code == null || code.trim().isEmpty()) {
Toast.makeText(this, "授权code为空,无法启动游戏", Toast.LENGTH_SHORT).show();
return;
}
// 检查游戏是否安装
if (!isAppInstalled("com.tencent.tmgp.sgame")) {
Toast.makeText(this, "未检测到王者荣耀,请先安装", Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent();
intent.setPackage("com.tencent.tmgp.sgame"); // 王者荣耀包名
intent.putExtra("code", code); // 传递授权code
// 可添加额外参数标识来源
intent.putExtra("source", getPackageName());
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "启动失败:未找到游戏应用", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (SecurityException e) {
Toast.makeText(this, "启动失败:权限不足", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (Exception e) {
Toast.makeText(this, "启动失败:" + e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
/**
* 检查应用是否安装
*
* @param packageName 应用包名
* @return 是否安装
*/
private boolean isAppInstalled(String packageName) {
try {
getPackageManager().getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 更新当前Activity的Intent
setIntent(intent);
// 处理授权回调
if (wxApi != null) {
wxApi.handleIntent(intent, this);
}
}
复制代码
作者:
海王
时间:
3 天前
代码要用代码块编辑发布,否则就会错乱的。
/**
* 启动游戏并传递授权code
*
* @param code 授权获取的code
*/
private void launchGameWithCode(String code) {
// 校验code合法性
if (code == null || code.trim().isEmpty()) {
Toast.makeText(this, "授权code为空,无法启动游戏", Toast.LENGTH_SHORT).show();
return;
}
// 检查游戏是否安装
if (!isAppInstalled("com.tencent.tmgp.sgame")) {
Toast.makeText(this, "未检测到王者荣耀,请先安装", Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent();
intent.setPackage("com.tencent.tmgp.sgame"); // 王者荣耀包名
intent.putExtra("code", code); // 传递授权code
// 可添加额外参数标识来源
intent.putExtra("source", getPackageName());
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "启动失败:未找到游戏应用", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (SecurityException e) {
Toast.makeText(this, "启动失败:权限不足", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (Exception e) {
Toast.makeText(this, "启动失败:" + e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
/**
* 检查应用是否安装
*
* @param packageName 应用包名
* @return 是否安装
*/
private boolean isAppInstalled(String packageName) {
try {
getPackageManager().getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 更新当前Activity的Intent
setIntent(intent);
// 处理授权回调
if (wxApi != null) {
wxApi.handleIntent(intent, this);
}
}
复制代码
作者:
最美好惊喜
时间:
3 天前
程序包管理器类
启动信息类
通知_被重新启动2
作者:
萧萧
时间:
前天 13:49
海王 发表于 2025-9-9 19:53
代码要用代码块编辑发布,否则就会错乱的。
好的
作者:
萧萧
时间:
前天 13:50
最美好惊喜 发表于 2025-9-9 22:39
程序包管理器类
启动信息类
通知_被重新启动2
OK 我去试试
欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/)
Powered by Discuz! X3.4