Share image to another app using Intent in android

后端 未结 2 2023
春和景丽
春和景丽 2020-12-21 21:47

I want to share image and text to another app but i\'m getting file format not supported when i\'m using this code please help...

 Uri picUri = Uri.parse(\"h         


        
相关标签:
2条回答
  • 2020-12-21 21:58

    The documentation for EXTRA_STREAM says that the Uri needs to have a content scheme. file usually also works, at least on Android 6.0 and older. Few apps will expect an http URL.

    0 讨论(0)
  • 2020-12-21 22:04

    try this

    private class myTask extends AsyncTask<Void, Void, Bitmap> {
    
    
        protected Bitmap doInBackground(Void... params) {
            Bitmap myBitmap=null;
            try {
                URL url = new URL(src);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream();
                myBitmap = BitmapFactory.decodeStream(input);
    
            } catch (IOException e) {
                // Log exception
            }
            return myBitmap;
        }
    
        @Override
        protected void onPostExecute(Bitmap result) {
            //do stuff
    
        }
    }
    
     Bitmap returned_bitmap = new myTask().execute().get()
    
    
    
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "download this image");
    String bitmapPath = Images.Media.insertImage(getContentResolver(), returned_bitmap,"title", null);
    Uri bitmapUri = Uri.parse(bitmapPath);    
    intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
    intent.setType("image/*");
    startActivity(Intent.createChooser(intent, "Share image via..."));
    
    0 讨论(0)
提交回复
热议问题