有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我在视图寻呼机中获取了当前图像位置,但无法从文件夹中获取图像

我已经尝试了所有的方法,但我无法从查看页面获取图像。我也得到了当前位置的图像。但即使我无法从文件夹中获取图像

public class quotes extends AppCompatActivity {

private ShareActionProvider mShareActionProvider;
Button btn;
ViewPager viewPager=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quotes_pager);
    btn = (Button) this.findViewById(R.id.share);

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new CustomPagerAdapter(this));

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/jpg");
            int position=viewPager.getCurrentItem();

            Uri uri = Uri.parse("@mipmap-hdpi/"+"apj"+position+".jpg");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(sharingIntent, "Share using"));
        }
    });
}
}

这是我的图像文件夹。我将我的图像保存在mip map文件夹中。有什么问题吗?如果没有,请告诉我如何使用查看寻呼机图像的当前位置从该文件夹获取图像

enter image description here


共 (1) 个答案

  1. # 1 楼答案

    无法从应用程序资产或资源文件夹共享图像,其他应用程序必须可以访问uri。 您需要将图像放入临时文件夹(而不是应用程序内部文件夹),然后通过intent发送。 检查此answer