仅在Android中共享所选图像

我如何使用用户选择的特定ID替换R.id.ic_launcher 我创建了一个代表图像网格视图的应用程序,然后在用户选择后选择特定图像,然后共享菜单按钮将图像共享给社交应用程序。 但错误是每当任何图像被选中并共享给任何应用程序时,它只发送默认的启动器图标,即ic_launcher.png 。 我的代码如下所示: FullImageActivity.java

 @SuppressLint("SdCardPath") public class FullImageActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.full_image); Intent i = getIntent(); int position = i.getExtras().getInt("id"); ImageAdapter imageAdapter = new ImageAdapter(this); ImageView imageView = (ImageView) findViewById(R.id.full_image_view); imageView.setImageResource(imageAdapter.mThumbIds[position]); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); File sd = Environment.getExternalStorageDirectory(); String fileName = "test.png"; File dest = new File(sd, fileName); try { FileOutputStream out; out = new FileOutputStream(dest); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } switch (item.getItemId()) { case R.id.item: Uri uri = Uri.fromFile(dest); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpeg"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share))); return true; default: return super.onOptionsItemSelected(item); } } 

这是我实现共享方法的地方,这是我的代码发送defautl ic_launcher.png而不是选择的图像。 此外,我将所有图像保存为ImageAdapter.java类中的.jpeg格式。

 private Context mContext; // Keeping all Images in array public Integer[] mThumbIds = { R.drawable.rage_0001,R.drawable.rage_0002, 

我的AndroidManifest.XML对于所有使用权限和活动记录都是这样的。

                                    

告诉我在哪里需要修改我的代码以便正确工作,如上所述。

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(),drawable.ic_launcher);//launcher being saved to file File sd = Environment.getExternalStorageDirectory(); String fileName = "test.png"; File dest = new File(sd, fileName); try { FileOutputStream out; out = new FileOutputStream(dest); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

这是将启动器图像保存到文件并因此共享该图像的部分