【问题标题】:Sharing Android text with the icon of my app使用我的应用程序图标共享 Android 文本
【发布时间】:2015-01-25 21:15:40
【问题描述】:

是否可以与我的应用程序的图标分享与此类似的文本?

因为我尝试这样做,但它适用于纯文本,但当我尝试使用图像时,它会共享整个图像,但我只想要一个小缩略图。 这是我的实际代码:

Intent intent2=new Intent(Intent.ACTION_SEND);

            intent2.setType("image/*"); 
            intent2.putExtra(Intent.EXTRA_TEXT,random); 
            Uri path = Uri.fromFile(new File(Image));
            intent2.putExtra(Intent.EXTRA_STREAM, path );
            startActivity(Intent.createChooser(intent2, "Share via"));

【问题讨论】:

    标签: android share thumbnails


    【解决方案1】:

    试试这个代码:

    Bitmap icon = mBitmap;
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/jpeg");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
    try {
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
    } catch (IOException e) {                       
            e.printStackTrace();
    }
    share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
    startActivity(Intent.createChooser(share, "Share Image"));
    

    【讨论】:

    • 我想使用我的应用程序的图标,而不是外部图像。
    • 所以试试这个:Uri imageUri = Uri.parse("android.resource://your.package/drawable/fileName"); sharedIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share);
    • 我已经像这样添加了你的代码:Uri imageUri = Uri.parse("android.resource://com.techappstudios.randomquotes" + "/drawable/"+ R.drawable.ic_launcher) ; intent2.putExtra(Intent.EXTRA_TEXT,random + "\n"+" 随机引用"); intent2.putExtra(Intent.EXTRA_STREAM, imageUri);但它会像一个完整的图像一样分享它,而不是缩略图......
    • 好的,使用这个解码器:Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath), THUMBSIZE, THUMBSIZE);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多