递归火山软件开发平台

标题: java这段用火山应该怎么写 [打印本页]

作者: 萧萧    时间: 3 天前
标题: java这段用火山应该怎么写
本帖最后由 萧萧 于 2025-9-10 13:52 编辑
  1. /**
  2. * 启动游戏并传递授权code
  3. *
  4. * @param code 授权获取的code
  5. */
  6. private void launchGameWithCode(String code) {
  7.     // 校验code合法性
  8.     if (code == null || code.trim().isEmpty()) {
  9.         Toast.makeText(this, "授权code为空,无法启动游戏", Toast.LENGTH_SHORT).show();
  10.         return;
  11.     }

  12.     // 检查游戏是否安装
  13.     if (!isAppInstalled("com.tencent.tmgp.sgame")) {
  14.         Toast.makeText(this, "未检测到王者荣耀,请先安装", Toast.LENGTH_SHORT).show();
  15.         return;
  16.     }

  17.     Intent intent = new Intent();
  18.     intent.setPackage("com.tencent.tmgp.sgame"); // 王者荣耀包名
  19.     intent.putExtra("code", code); // 传递授权code
  20.     // 可添加额外参数标识来源
  21.     intent.putExtra("source", getPackageName());

  22.     try {
  23.         startActivity(intent);
  24.     } catch (ActivityNotFoundException e) {
  25.         Toast.makeText(this, "启动失败:未找到游戏应用", Toast.LENGTH_SHORT).show();
  26.         e.printStackTrace();
  27.     } catch (SecurityException e) {
  28.         Toast.makeText(this, "启动失败:权限不足", Toast.LENGTH_SHORT).show();
  29.         e.printStackTrace();
  30.     } catch (Exception e) {
  31.         Toast.makeText(this, "启动失败:" + e.getMessage(), Toast.LENGTH_SHORT).show();
  32.         e.printStackTrace();
  33.     }
  34. }

  35. /**
  36. * 检查应用是否安装
  37. *
  38. * @param packageName 应用包名
  39. * @return 是否安装
  40. */
  41. private boolean isAppInstalled(String packageName) {
  42.     try {
  43.         getPackageManager().getPackageInfo(packageName, 0);
  44.         return true;
  45.     } catch (PackageManager.NameNotFoundException e) {
  46.         return false;
  47.     }
  48. }

  49. @Override
  50. protected void onNewIntent(Intent intent) {
  51.     super.onNewIntent(intent);
  52.     // 更新当前Activity的Intent
  53.     setIntent(intent);
  54.     // 处理授权回调
  55.     if (wxApi != null) {
  56.         wxApi.handleIntent(intent, this);
  57.     }
  58. }
复制代码


作者: 海王    时间: 3 天前
代码要用代码块编辑发布,否则就会错乱的。

  1. /**
  2. * 启动游戏并传递授权code
  3. *
  4. * @param code 授权获取的code
  5. */
  6. private void launchGameWithCode(String code) {
  7.     // 校验code合法性
  8.     if (code == null || code.trim().isEmpty()) {
  9.         Toast.makeText(this, "授权code为空,无法启动游戏", Toast.LENGTH_SHORT).show();
  10.         return;
  11.     }

  12.     // 检查游戏是否安装
  13.     if (!isAppInstalled("com.tencent.tmgp.sgame")) {
  14.         Toast.makeText(this, "未检测到王者荣耀,请先安装", Toast.LENGTH_SHORT).show();
  15.         return;
  16.     }

  17.     Intent intent = new Intent();
  18.     intent.setPackage("com.tencent.tmgp.sgame"); // 王者荣耀包名
  19.     intent.putExtra("code", code); // 传递授权code
  20.     // 可添加额外参数标识来源
  21.     intent.putExtra("source", getPackageName());

  22.     try {
  23.         startActivity(intent);
  24.     } catch (ActivityNotFoundException e) {
  25.         Toast.makeText(this, "启动失败:未找到游戏应用", Toast.LENGTH_SHORT).show();
  26.         e.printStackTrace();
  27.     } catch (SecurityException e) {
  28.         Toast.makeText(this, "启动失败:权限不足", Toast.LENGTH_SHORT).show();
  29.         e.printStackTrace();
  30.     } catch (Exception e) {
  31.         Toast.makeText(this, "启动失败:" + e.getMessage(), Toast.LENGTH_SHORT).show();
  32.         e.printStackTrace();
  33.     }
  34. }

  35. /**
  36. * 检查应用是否安装
  37. *
  38. * @param packageName 应用包名
  39. * @return 是否安装
  40. */
  41. private boolean isAppInstalled(String packageName) {
  42.     try {
  43.         getPackageManager().getPackageInfo(packageName, 0);
  44.         return true;
  45.     } catch (PackageManager.NameNotFoundException e) {
  46.         return false;
  47.     }
  48. }

  49. @Override
  50. protected void onNewIntent(Intent intent) {
  51.     super.onNewIntent(intent);
  52.     // 更新当前Activity的Intent
  53.     setIntent(intent);
  54.     // 处理授权回调
  55.     if (wxApi != null) {
  56.         wxApi.handleIntent(intent, this);
  57.     }
  58. }
复制代码


作者: 最美好惊喜    时间: 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