【问题标题】:sharing photo from android app从安卓应用分享照片
【发布时间】:2013-10-23 13:23:51
【问题描述】:

我开发了一个壁纸应用程序,我想在其中添加分享按钮以在 whatsapp 上分享照片。这是我的代码(但该代码仅适用于任何文本消息)我想分享一张照片。

请回复我可以从我的应用程序中选择壁纸并发送给whatsapp的特定联系人的代码。

case R.id.save:
        InputStream y11 = getResources().openRawResource(to);
        Bitmap b11 = BitmapFactory.decodeStream(y11);
        Intent waIntent = new Intent(Intent.ACTION_SEND);
        waIntent.setType("image/*");

        waIntent.setPackage("com.whatsapp.android");
        waIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, to);
        startActivity(Intent.createChooser(waIntent, "Share with"));

【问题讨论】:

    标签: android share wallpaper whatsapp


    【解决方案1】:

    替换

    waIntent.setType("text/plain");
    

    waIntent.setType("image/png");
    

    【讨论】:

    • 我刚刚编辑了我的代码。我在其中放置了 image/* 但它无法正常工作。
    • 这里的“to”是什么:waIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, to);
    • 好的。 “to”是我的图片来源。 int to=R.drawable.1 或 R.drawable.2 等
    • 如果我运行上面的代码,我会收到“没有应用程序可以执行此操作”的错误。我的设备中有什么应用程序
    • 尝试使用 image/png 代替 image/*
    【解决方案2】:

    包名错误。试试:com.whatsapp 这段代码是通过whatsapp分享图片

    private void shareIt(Uri uri) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/*");
            sharingIntent.setPackage("com.whatsapp");
            sharingIntent.putExtra(Intent.EXTRA_TEXT,"Shared via my app");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(sharingIntent, "share with"));
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      相关资源
      最近更新 更多