2017-02-08 62 views
-1

我做了一個功能的應用程序,與社交媒體分享新聞 哪裏有新聞內容和新聞圖片。我試圖遵循一些教程,但仍然無法成功完成。如何製作功能在社交媒體中分享內容?

到目前爲止,新聞內容沒有圖像發送。這是我的代碼:

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
sharingIntent.setType("*/*"); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, tittle_selected); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, catagory_selected); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, date_selected); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, news_selected); 
sharingIntent.putExtra(Intent.EXTRA_STREAM, image_selected); 
startActivity(Intent.createChooser(sharingIntent,"Share using")); 

回答

0

做這樣的:

ImageView image = (ImageView) findViewById(R.id.yourImage); 
    final Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); 

    try{ 
     new AsyncTask<String, String, String>(){ 
      @Override 
      protected String doInBackground(String... params){ 
       String url = null; 
       try{ 
        url= MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, o.getHeading(), o.getDescription()); 
       } catch (Exception e){ 
        e.printStackTrace(); 
       } 
       return url; 
      } 

      @Override 
      public void onPostExecute(String url){ 
       if(url != null){ 
        Intent sharingIntent = new Intent(); 
        sharingIntent.setAction(Intent.ACTION_SEND); 
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, tittle_selected); 
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, catagory_selected); 
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, date_selected); 
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, news_selected); 
        sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); 
        sharingIntent.setType("image/*"); 
        sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
        startActivity(Intent.createChooser(sharingIntent, "Share")); 
       } else { 
        Toast.makeText(context, "Oops, a problem occurred while sharing. Check permission for this app.", Toast.LENGTH_LONG).show(); 
       } 
      } 
     }.execute(); 
    } catch (Exception e){ 
     e.printStackTrace(); 
    } 
0

這是意圖如何在共享數據用於任何媒體

Intent sendIntent = new Intent(); 
        sendIntent.setAction(Intent.ACTION_SEND); 
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); 
        sendIntent.setType("text/plain"); 
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));