簡體   English   中英

如何通過MMS或任何社交媒體應用程序從android應用程序發送可繪制圖像?

[英]How to send drawable Images from android app as MMS or on any social media app?

我無法從應用程序共享我的圖像以作為附件進行消息傳遞,但我有一組可繪制圖像的int數組

final int [] imagelistId={
        R.drawable.birthday1,
        R.drawable.birthday2,
        R.drawable.birthday3,
        R.drawable.birthday4,
        R.drawable.birthday5,
        R.drawable.birthday6,
    };

之后,我有此代碼用於共享圖像作為附件

smsBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
                // add the message at the sms_body extra field
                smsIntent.setData(Uri.parse("mmsto:"));
                smsIntent.setType("image/*");
                smsIntent.putExtra("sms_body", "Image");
                smsIntent.putExtra("subject", "Image Message");
                smsIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.example.finalgreetings/" + imagelistId[pos]) );
                try{
                    mcontext.startActivity(smsIntent);
                } catch (Exception ex) {
                    Toast.makeText(mcontext, "Your sms has failed...",
                            Toast.LENGTH_LONG).show();
                    ex.printStackTrace();
                }
            }
        });

我已經看到很多堆棧溢出問題,但沒有一個回答我的問題。 我也讀過有關將可繪制圖形轉換為位圖並保存到內部或外部存儲,然后共享的信息,但不知道該怎么做。 請給我最好的和簡單的解決方案。 提前感謝。

嘗試這個..!!!

smsBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {               
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourimage);//put here your image id
                String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/LatestShare.png";
                OutputStream out = null;
                File file = new File(path);
                try {
                    out = new FileOutputStream(file);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                    out.flush();
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                path = file.getPath();
                Uri bmpUri = Uri.parse("file://" + path);
                Intent shareIntent = new Intent();
                shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                shareIntent.setType("image/png");
                startActivity(Intent.createChooser(shareIntent, "Share with"));

        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM