【发布时间】:2015-04-24 07:52:31
【问题描述】:
我想在社交应用上发布我的游戏屏幕截图。我使用 Libgdx 框架开发了这个游戏。我在 Core 类中创建了一个接口。这是它的 Intent 共享特定代码。
public interface ActionResolver {
public void shareit();
}
然后在我的 Androidlauncher 类上实现它
public class AndroidLauncher extends AndroidApplication implements
ActionResolver{ .......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = initializeForView(new MainGame(this),
new AndroidApplicationConfiguration());// View
}
@Override public void shareScreen() {
String message = "Text I want to share."; Intent share = new
Intent(Intent.ACTION_SEND); share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(share,
"Title of the dialog the system will open"));
}
public void createIntent(View v){
{ // View view =gameView.getRootView(); Bitmap icon =
getBitmapFromView(v.getRootView()); Intent share = new
Intent(Intent.ACTION_SEND); share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "title");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri =
getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
OutputStream outstream;
try { outstream = getContentResolver().openOutputStream(uri);
icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close(); } catch (Exception e) {
System.err.println(e.toString()); }
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image")); } }
public void createIntent(View v){
Bitmap icon = getBitmapFromView(v.getRootView()); Intent share = new
Intent(Intent.ACTION_SEND); share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "title");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri =
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
}
public static Bitmap getBitmapFromView(View view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return returnedBitmap;
}
我还在 MainGame 类中初始化我的界面
public MainGame(ActionResolver actionResolver) {
super();
this.actionResolver = actionResolver;
我很困惑的一件事我应该通过哪个视图来启动这个意图?因为它的 libgdx 框架。其次在Android方面显然Canvas,Bitmap都来自Android。
使用这整个代码,我可以开始我的意图,但是当我共享屏幕时,屏幕只是一个黑屏。但是该屏幕的底部出现了一个我已经通过 admob 使用的广告。
我在这里搜索了很多,找到了分享黑屏的相关帖子,而不是游戏的实际屏幕截图。但我不明白这一切,因为有些人要求使用一些不同的库。我不想为 facebook 使用任何外部库或 facebook sdk。我只想要简单的 android Intent 来分享 Screen 。请帮帮我。
【问题讨论】:
-
@Michaël Demey 是的,我已经检查过这些问题。事情是这里的画布,android 的视图和布局将调用所有这些 libgdx 框架的布局。这就是为什么我得到一个黑色的屏幕截图。而且我不知道该怎么办。
标签: android libgdx screenshot screensharing