簡體   English   中英

如何使用Android Studio中的共享按鈕共享圖像?

[英]How to share Image using share button in Android Studio?

我已經在我的Gif圖像應用程序上插入了共享按鈕,它工作得很好,但是使用共享按鈕為共享圖像進行編碼時遇到了問題。

這是我在主要活動中的代碼:

GridView gridView;
private int[] gifImages = {R.drawable.pb_1, R.drawable.pb_2, R.drawable.pb_3, R.drawable.pb_4, R.drawable.pb_5, R.drawable.pb_6, ....);

這是我在GridItemActivity中的代碼:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid_item);

    image = findViewById(R.id.imageView);

    Intent intent = getIntent();
    image.setImageResource(intent.getIntExtra("image", 0));
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return super.onCreateOptionsMenu(menu);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.share_button:
            Uri mImageUri = Uri.parse(getResources().getDrawable(R.drawable.pb_1).toString());
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/gif");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, mImageUri);
            startActivity(Intent.createChooser(sharingIntent, "Share Using"));
            break;
    }

    return super.onOptionsItemSelected(item);
}

}

不幸的是,它不起作用...

誰能幫幫我嗎?

檢查是https://developer.android.com/training/sharing/send

閱讀本文檔的以下主題

  • 發送二進制內容
  • 發送多條內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM