0

ゲームのスクリーン ショットをソーシャル アプリに投稿したいと考えています。Libgdx フレームワークを使用してこのゲームを開発しました。Core クラスにインターフェイスを作成しました。これがそのインテント共有固有のコードです。

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;

私が混乱していることの1つは、このインテントを開始するためにどのビューを渡す必要があるか? その libgdx フレームワークのためです。第二に、Android 側では明らかに Canvas、Bitmap はすべて Android からのものです。

このコード全体で意図を開始できますが、画面を共有すると画面がただの黒い画面になります。しかし、その画面の下部には、admob で既に使用している広告が表示されます。

ここでよく検索しましたが、実際のゲームのスクリーンショットではなく、黒い画面を共有する関連スレッドを見つけました。しかし、いくつかの異なるライブラリを使用するように求めている人もいるため、私はそれをすべて理解していません。Facebook用の外部ライブラリやFacebook SDKを使用したくありません。シンプルな Android Intent で Screen を共有したいだけです。親切に私を助けてください。

4

1 に答える 1

1

com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap は私にとってはうまくいきます。

https://github.com/libgdx/libgdx/wiki/Take-a-Screenshot

于 2015-04-24T09:26:45.990 に答える