【问题标题】:libGDX: Share-button to share a simple String in e.g. Facebook, E-Mail, WhatsApp, TwitterlibGDX:共享按钮,用于共享一个简单的字符串,例如脸书、电子邮件、WhatsApp、推特
【发布时间】:2017-10-25 19:45:19
【问题描述】:

我的申请有一点问题,希望有人能帮助我。 我想分享我游戏中的一个简单字符串,例如社交网络 通过点击一个按钮。我将 libGDX 与 Android Studio 一起使用。

感谢您提供有用的答案! :)

【问题讨论】:

    标签: android libgdx share social-networking


    【解决方案1】:

    根据您的要求使用interfacing

    1. 在核心模块中创建接口

      public interface Services {
      
         void share();
      } 
      
    2. 实现AndroidLauncher类的上述接口并编写实现,将实现类的对象共享给核心模块,并从核心模块调用共享方法

      @Override
      public void share() {
      
          Intent sharingIntent = new Intent(Intent.ACTION_SEND);
          sharingIntent.setType("text/plain");
          sharingIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.app_name);
      
          String sAux = "\nLet me recommend you this game\n\n";
          sAux = sAux + AppInfo.PLAYSTORE_LINK+getPackageName()+" \n\n";
      
          sharingIntent.putExtra(Intent.EXTRA_TEXT, sAux);
          startActivity(Intent.createChooser(sharingIntent, "Share via"));
      
      }
      

    编辑

    • PLAYSTORE_LINK 是我的AppInfo 类中的静态常量字符串,您可以保留在自己的类中,也可以替换为字符串值。

      public static final String PLAYSTORE_LINK= "https://play.google.com/store/apps/details?id=";
      
    • 您有两个接口,并且您在 ApplicationListener 实现的类中使用了这两个接口引用。

      1. 要么创建两个接口的父接口,然后用父接口实现AndroidLauncher类,并在ApplicationListener实现的类中捕获引用,向下转换并调用各自的方法。

      2. 在构造函数中传递两个参数并在核心模块中保持引用,然后调用方法。

    • 保留参考

      public class GdxTest extends ApplicationAdapter{
      
          Service service;
      
        public GdxTest(Service service) {
           this.service=service;
        }
      }     
      
    • 将侦听器添加到您的对象

      TextButton x= new TextButton("SHARE",skin);
      x.addListener(new ClickListener(){
          @Override
          public void clicked(InputEvent event, float x, float y) {
              service.share();
              super.clicked(event, x, y);
          }
      });
      

    【讨论】:

    • 很好,谢谢。它在我的代码中看起来几乎不错,但是 1. 我如何实现 2 个接口,因为我的 AndroidLauncher 中需要 2 个接口和 2.“AppInfo”给我一个错误,并带有“无法解析符号 'AppInfo'”的注释。
    • 至少我该如何调用那几行代码,因为我想通过点击按钮来共享字符串
    【解决方案2】:
     btn_share.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
    
               Gdx.net.openURI("http://share_adress.html");
    
                super.clicked(event, x, y);
            }
        });
    

    【讨论】:

    • 虽然这可能会解决最初的问题,但最好包含对您的代码的描述,以便我们知道发生了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 2020-06-17
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    相关资源
    最近更新 更多