zoukankan      html  css  js  c++  java
  • 团队冲刺第二阶段10

    今天做了最后分享的功能,组员之间整合了代码,测试各部分的功能实现。

      public void shareNote (Note note) {
    
        String titleText = note.getTitle();
    
        String contentText = titleText
            + System.getProperty("line.separator")
            + note.getContent();
    
        Intent shareIntent = new Intent();
        // Prepare sharing intent with only text
        if (note.getAttachmentsList().isEmpty()) {
          shareIntent.setAction(Intent.ACTION_SEND);
          shareIntent.setType("text/plain");
    
          // Intent with single image attachment
        } else if (note.getAttachmentsList().size() == 1) {
          shareIntent.setAction(Intent.ACTION_SEND);
          Attachment attachment = note.getAttachmentsList().get(0);
          shareIntent.setType(attachment.getMime_type());
          shareIntent.putExtra(Intent.EXTRA_STREAM, FileProviderHelper.getShareableUri(attachment));
    
          // Intent with multiple images
        } else if (note.getAttachmentsList().size() > 1) {
          shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
          ArrayList<Uri> uris = new ArrayList<>();
          // A check to decide the mime type of attachments to share is done here
          HashMap<String, Boolean> mimeTypes = new HashMap<>();
          for (Attachment attachment : note.getAttachmentsList()) {
            uris.add(FileProviderHelper.getShareableUri(attachment));
            mimeTypes.put(attachment.getMime_type(), true);
          }
          // If many mime types are present a general type is assigned to intent
          if (mimeTypes.size() > 1) {
            shareIntent.setType("*/*");
          } else {
            shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
          }
    
          shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        }
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
        shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);
    
        startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser)));
      }

  • 相关阅读:
    if()中的判断条件为什么被判断不通过
    2016-10-1219:50:40
    学习C语言主流编译器的使用方法
    请帮忙看下为什么返回值不正确
    puts()和putchar()的差异
    这题的最短路线怎么求~
    各路大神大显神通!帮帮忙如何使用顺序表实现以下任务
    网络协议学习笔记(九)CDN和数据中心
    网络协议学习笔记(八)DNS协议和HttpDNS协议
    网络协议学习笔记(七)流媒体协议和P2P协议
  • 原文地址:https://www.cnblogs.com/xjmm/p/13085539.html
Copyright © 2011-2022 走看看