【发布时间】:2017-10-25 19:45:19
【问题描述】:
我的申请有一点问题,希望有人能帮助我。 我想分享我游戏中的一个简单字符串,例如社交网络 通过点击一个按钮。我将 libGDX 与 Android Studio 一起使用。
感谢您提供有用的答案! :)
【问题讨论】:
标签: android libgdx share social-networking
我的申请有一点问题,希望有人能帮助我。 我想分享我游戏中的一个简单字符串,例如社交网络 通过点击一个按钮。我将 libGDX 与 Android Studio 一起使用。
感谢您提供有用的答案! :)
【问题讨论】:
标签: android libgdx share social-networking
根据您的要求使用interfacing
在核心模块中创建接口
public interface Services {
void share();
}
实现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 实现的类中使用了这两个接口引用。
要么创建两个接口的父接口,然后用父接口实现AndroidLauncher类,并在ApplicationListener实现的类中捕获引用,向下转换并调用各自的方法。
在构造函数中传递两个参数并在核心模块中保持引用,然后调用方法。
保留参考
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);
}
});
【讨论】:
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);
}
});
【讨论】: