最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自帶API實(shí)現(xiàn)分享功能

 更新時(shí)間:2018年04月25日 16:31:16   作者:夏沫凡塵  
這篇文章主要為大家詳細(xì)介紹了Android自帶API實(shí)現(xiàn)分享功能,實(shí)現(xiàn)文字和圖片的分享,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

在做項(xiàng)目的過程中需要實(shí)現(xiàn)文字和圖片的分享,有兩種方式:
1. 使用android sdk中自帶的Intent.ACTION_SEND實(shí)現(xiàn)分享。
2. 使用shareSDK、友盟等第三方的服務(wù)。
鑒于使用的方便,此次只介紹使用Android sdk中自帶的方式來實(shí)現(xiàn)分享的功能。

分享文字

/** 
   * 分享文字內(nèi)容 
   * 
   * @param dlgTitle 
   *      分享對話框標(biāo)題 
   * @param subject 
   *      主題 
   * @param content 
   *      分享內(nèi)容(文字) 
   */ 
private void shareText(String dlgTitle, String subject, String content) { 
    if (content == null || "".equals(content)) { 
      return; 
    } 
    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("text/plain"); 
    if (subject != null && !"".equals(subject)) { 
      intent.putExtra(Intent.EXTRA_SUBJECT, subject); 
    } 

    intent.putExtra(Intent.EXTRA_TEXT, content); 

    // 設(shè)置彈出框標(biāo)題 
    if (dlgTitle != null && !"".equals(dlgTitle)) { // 自定義標(biāo)題 
      startActivity(Intent.createChooser(intent, dlgTitle)); 
    } else { // 系統(tǒng)默認(rèn)標(biāo)題 
      startActivity(intent); 
    } 
  } 

分享單張圖片

/** 
   * 分享圖片和文字內(nèi)容 
   * 
   * @param dlgTitle 
   *      分享對話框標(biāo)題 
   * @param subject 
   *      主題 
   * @param content 
   *      分享內(nèi)容(文字) 
   * @param uri 
   *      圖片資源URI 
   */ 
  private void shareImg(String dlgTitle, String subject, String content, 
      Uri uri) { 
    if (uri == null) { 
      return; 
    } 
    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType("image/*"); 
    intent.putExtra(Intent.EXTRA_STREAM, uri); 
    if (subject != null && !"".equals(subject)) { 
      intent.putExtra(Intent.EXTRA_SUBJECT, subject); 
    } 
    if (content != null && !"".equals(content)) { 
      intent.putExtra(Intent.EXTRA_TEXT, content); 
    } 

    // 設(shè)置彈出框標(biāo)題 
    if (dlgTitle != null && !"".equals(dlgTitle)) { // 自定義標(biāo)題 
      startActivity(Intent.createChooser(intent, dlgTitle)); 
    } else { // 系統(tǒng)默認(rèn)標(biāo)題 
      startActivity(intent); 
    } 
  } 

分享多張圖片

//分享多張圖片 
  public void shareMultipleImage(View view) { 
    ArrayList<Uri> uriList = new ArrayList<>(); 

    String path = Environment.getExternalStorageDirectory() + File.separator; 
    uriList.add(Uri.fromFile(new File(path+"australia_1.jpg"))); 
    uriList.add(Uri.fromFile(new File(path+"australia_2.jpg"))); 
    uriList.add(Uri.fromFile(new File(path+"australia_3.jpg"))); 

    Intent shareIntent = new Intent(); 
    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); 
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList); 
    shareIntent.setType("image/*"); 
    startActivity(Intent.createChooser(shareIntent, "分享到")); 
  } 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

兴安盟| 芦山县| 迭部县| 灵台县| 博白县| 海门市| 旌德县| 台南县| 南部县| 蓬溪县| 吴旗县| 包头市| 陇南市| 巴塘县| 西安市| 巴林右旗| 定结县| 南雄市| 新民市| 惠州市| 鹤峰县| 大城县| 桓仁| 梁平县| 渝中区| 南部县| 汕头市| 阿城市| 滕州市| 富阳市| 娄烦县| 通海县| 沿河| 磐安县| 宁强县| 衡山县| 临夏县| 宁阳县| 视频| 扬州市| 南城县|