Sharing URL to Facebook, Twitter and email in Android?

前端 未结 7 1185
野趣味
野趣味 2021-01-30 16:16

Is there anything similar to getsharekit.com for Android? It allows to share URL\'s to social networking sites. Is there anything similar to this or do I need to code separately

7条回答
  •  执笔经年
    2021-01-30 16:59

    // for URL

    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain");
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
    share.putExtra(Intent.EXTRA_TEXT, "http://www.codeofaninja.com");
    startActivity(Intent.createChooser(share, "Share link!"));
    

    // for image

    Intent share = new Intent(Intent.ACTION_SEND);
    // If you want to share a png image only, you can do:
    // setType("image/png"); OR for jpeg: setType("image/jpeg");
    share.setType("image/*");
    
    // Make sure you put example png image named myImage.png in your
    // directory
    String imagePath = Environment.getExternalStorageDirectory()
            + "/myImage.png";
    
    File imageFileToShare = new File(imagePath);
    Uri uri = Uri.fromFile(imageFileToShare);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share Image!"));
    

提交回复
热议问题