Too many Android models Update too quickly Crash logs cannot be collected

Please refer to Demo: sendmail-demo

Collect crash logs

Often get APP crashes, but in the test environment is fine again. When it comes to models and Android versions, the company doesn’t have one. Let the user take a video or screen. I can’t reproduce it. I can’t see the crash log. So think of logging a crash.

*/ @override public void UncaughtException (Thread Thread, Throwable ex) {if(! handleException(ex) && mDefaultHandler ! = null) {/ / if the user does not deal with the system default exception handler to handle mDefaultHandler. UncaughtException (thread, the ex); }else{ SystemClock.sleep(3000); / / exit android OS. Process. KillProcess (android. OS. Process. MyPid ()); System.exit(1); }}Copy the code

When a crash occurs, log the crash to a local file and save it for 5 days.

Send crash logs

Let users send crash logs when they report crashes. It’s fine. See the crash.

/** * create message ** @ with attachmentreturn*/ private Message createAttachmentMail(final Mail info, List<File> fileList) { Properties pro = info.getProperties(); try { Session sendMailSession = Session.getInstance(pro, newAuthenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
          returnnew PasswordAuthentication(info.getUserName(), info.getPassword()); }}); message = new MimeMessage(sendMailSession); Address from = new InternetAddress(info.getFromAddress()); // Set the sender of the mail message message.setFrom(from); // Create the recipient address of the message and set it to the message messagesetAddress(message,info); // Message title message.setSubject(info.getSubject()); MimeMultipart mp = new MimeMultipart("mixed"); message.setContent(mp); CharSet= utF-8 MimeBodyPart text = new MimeBodyPart(); text.setContent(info.getContent(),"text/html; charset=UTF-8"); mp.addBodyPart(text); // Create a mail attachmentif(null ! = fileList && 0 < fileList.size()) {for (File file : fileList) {
          MimeBodyPart attach = new MimeBodyPart();

          FileDataSource ds = new FileDataSource(file);
          DataHandler dh = new DataHandler(ds);
          attach.setDataHandler(dh);
          attach.setFileName(MimeUtility.encodeText(dh.getName(), "UTF-8"."B"));
          mp.addBodyPart(attach);
        }
      }

      message.saveChanges();

      // add handlers for main MIME types
      MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
      mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
      mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
      mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
      mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
      mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
      CommandMap.setDefaultCommandMap(mc);

    } catch (Exception e) {
      Log.e("TAG"."Failed to create message with attachment"); e.printStackTrace(); } // Returns the generated messagereturn message;
  }
Copy the code

Three, pay attention

The crash logging implementation is downloaded from the Internet and can be used directly. 1. Tencent Enterprise Email If you use Tencent enterprise email, then it is suggested to change your own email, such as 126 or 163. Otherwise, an authorization failure message is displayed. #####2. jar problems using javaMail JAR, there are many ways to download, and there are many packages. So when choosing a package, it’s best to match it. You can use the DEMO JAR package directly. #####3. Attachment MIME TYP problem everything is ok, upload attachment report mimeType problem, need to add next.

// add handlers for main MIME types
      MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
      mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
      mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
      mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
      mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
      mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
      CommandMap.setDefaultCommandMap(mc);
Copy the code

4. Environmental issues

When using jar packages that have been tested many times and rely on third-party libraries many times, Java Mail has too many dependencies and conflicts often occur. Be clear about the contents of the ~/. Gradle /caches folder.

5. Demo

When using Demo, you need to change the recipient and sender addresses. The sender’s password, be sure to use authorization code. The authentication code can be obtained in different ways according to different email addresses. It is not recommended to use Tencent’S wechat binding security code, because multiple attempts fail. Email box 163 or 126 is recommended, which can be clearly seen in the Settings after login.

The address of DEMO, remember star. Please refer to Demo: sendmail-demo

Life is a long road, the road you choose, no matter how difficult it is, must continue.