2017-07-09 135 views
0

是否有可能使用android共享對話框將圖像和文本共享到Facebook,Instagram和WhatsApp?我正在嘗試2周,但沒有成功。我唯一能做的就是在不使用共享對話框的情況下編寫一些foreach媒體代碼。這是一些代碼,與WhatsApp的工作,但不能與斯塔和Facebook使用android共享對話框共享圖像和文本

String DishImage = listDishes.get(selectedDish).getDishImage(); 
      Picasso.with(this).load(DishImage).into(new Target() { 
       @Override 
       public void onBitmapLoaded(Bitmap bm, Picasso.LoadedFrom from) { 
        OutputStream fOut = null; 
        Uri outputFileUri; 
        try { 
         File root = new File(Environment.getExternalStorageDirectory() + File.separator + "FoodMana" + File.separator); 
         root.mkdirs(); 
         File sdImageMainDirectory = new File(root, "myPicName.jpg"); 
         fOut = new FileOutputStream(sdImageMainDirectory); 
        } catch (Exception e) {Toast.makeText(getApplicationContext(), "Error occured. Please try again later.", Toast.LENGTH_SHORT).show();} 

        try { 
         bm.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
         fOut.flush(); 
         fOut.close(); 
        } catch (Exception e) { 
        } 


         Intent waIntent = new Intent(android.content.Intent.ACTION_SEND); 
         waIntent.setType("image/*"); 
         waIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory() 
           + File.separator + "FoodMana" + File.separator + "myPicName.jpg")); 
         waIntent.putExtra(Intent.EXTRA_TEXT, "I am going to eat that dish!!!!!" + "\n" + "what do you think? check out"); 
         startActivity(Intent.createChooser(waIntent, "Share with")); 

       } 

       @Override 
       public void onBitmapFailed(Drawable errorDrawable) { 
        Log.d("TAG","error"); 
       } 

       @Override 
       public void onPrepareLoad(Drawable placeHolderDrawable) { 
        Log.d("TAG","prepared"); 

       } 
      }); 

回答

0

我使用這everwhere共享一個鏈接 我正在從al_details.get(getLayoutPosition()).get(URL_WEB).toString()

share.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
        Intent shareintent = new Intent(Intent.ACTION_SEND); 
        shareintent.setType("text/plain"); 
        shareintent.putExtra(Intent.EXTRA_TEXT,al_details.get(getLayoutPosition()).get(URL_WEB).toString()); 
        mContext.startActivity(Intent.createChooser(shareintent,"Share Via")); 
        } 
       }); 

我的鏈接我試過許多東西互聯網,但最終我做到了。所以你可以嘗試一次。

0

OK我找到了解決辦法

String DishImage = listDishes.get(selectedDish).getDishImage(); 
      Picasso.with(this).load(DishImage).into(new Target() { 
       @Override 
       public void onBitmapLoaded(Bitmap bm, Picasso.LoadedFrom from) { 
        Intent intent = new Intent(Intent.ACTION_SEND); 
        intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image"); 
        String path = null; 
        path = MediaStore.Images.Media.insertImage(getContentResolver(), bm, "", null); 
        Uri screenshotUri = Uri.parse(path); 
        intent.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
        intent.setType("image/*"); 
        startActivity(Intent.createChooser(intent, "Share image via...")); 
       } 
       @Override 
       public void onBitmapFailed(Drawable errorDrawable) { 
        Log.d("TAG","error"); 
       } 
       @Override 
       public void onPrepareLoad(Drawable placeHolderDrawable) { 
        Log.d("TAG","prepared"); 
       } 
      });