【问题标题】:Share option not working for Marshmallow [android]共享选项不适用于 Marshmallow [android]
【发布时间】:2016-12-15 18:13:43
【问题描述】:

我从 Json 获取图像并将其显示在网格视图中。在选择图像时,图像会放大到全屏并提供共享选项。当我单击共享选项时,在 API 22 以上的手机上,加载栏不会消失。它在棒棒糖之前都很好用。不知道为什么它在 Marshmallow 中不起作用。

这里是代码

    public void share(View view){
    // Get access to the URI for the bitmap
    pDialog = new ProgressDialog(Displaydemo.this);
    pDialog.setMessage("Loading...");
    pDialog.show();
    niv1 = (NetworkImageView) findViewById(R.id.imgNetwork);
    Uri bmpUri = getLocalBitmapUri(niv1);
    if (bmpUri != null) {

        pDialog.dismiss();
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT,"share");
        shareIntent.putExtra(Intent.EXTRA_TEXT,Datas.Address );
        shareIntent.setType("image/*");
        startActivity(Intent.createChooser(shareIntent, "Share Image"));
    }
}

【问题讨论】:

    标签: android


    【解决方案1】:

    看起来您正面临 mashmallow 运行时权限问题。请参考此帖Android 6: cannot share files anymore?

    另外,如果使用 v4 支持库,你应该使用 ShareCompat 来代替https://medium.com/google-developers/sharing-content-between-android-apps-2e6db9d1368b#.wnlh9s3n7

    【讨论】:

    • 如何设置路径xml文件。
    • @Sreepulari “如何设置路径 xml 文件”是什么意思?
    • 设置路径 res/xml/filepath.xml
    【解决方案2】:

    字符串路径 = Environment.getExternalStorageDirectory() + File.separator + File.separator +file_name;

    文件文件_ =新文件(路径);

    private void shareFile(File file_) { Intent intentShareFile = new Intent(Intent.ACTION_SEND);

        intentShareFile.setType(URLConnection.guessContentTypeFromName(file_.getName()));
        intentShareFile.putExtra(Intent.EXTRA_STREAM,
                Uri.parse("file://"+file_.getAbsolutePath()));
    
        startActivity(Intent.createChooser(intentShareFile, "Share File"));
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-15
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      • 2013-10-12
      相关资源
      最近更新 更多