Android studio 如何在android studio中导入Sendgrid

Android studio 如何在android studio中导入Sendgrid,android-studio,google-cloud-endpoints,sendgrid,Android Studio,Google Cloud Endpoints,Sendgrid,我想使用sendgrid从我的google endpoint项目发送电子邮件,我正在android studio中开发该项目。 问题是,我找不到任何导入sendgrid库的示例,我尝试了以下方法和其他一些变体: compile 'com.sendgrid:1.0.6' 其中1.0.6是最新版本?我可以找到答案: compile 'com.sendgrid:sendgrid-java:2.2.2' 在中,cfl的答案实际上不适用于最新版本的Android Studio。使用Send Grid

我想使用sendgrid从我的google endpoint项目发送电子邮件,我正在android studio中开发该项目。 问题是,我找不到任何导入sendgrid库的示例,我尝试了以下方法和其他一些变体:

compile 'com.sendgrid:1.0.6'
其中1.0.6是最新版本?我可以找到答案:

compile 'com.sendgrid:sendgrid-java:2.2.2'

中,cfl的答案实际上不适用于最新版本的Android Studio。使用Send Grid java依赖项与Android Studio固有的各种依赖项冲突。谢天谢地,我找到了Dany Santiago制作的分叉版本。在他的示例中,他使用用户名和密码来实例化SendGrid对象,但如果您有API密钥,则可以使用该密钥来避免将帐户信息保存在设备上。将此添加到Android Studio项目的build.gradle(应用程序)中的依赖项:

    compile 'com.github.danysantiago:sendgrid-android:1'
不要将sendgrid java与Android Studio一起使用,它将不起作用。有关更多信息,请访问以下链接

此外,您不需要使用链接中使用的示例。如果您有sendgrid的API密钥,则此示例代码可以正常工作:

    //Might need other imports
    import com.sendgrid.SendGrid;
    import com.sendgrid.SendGridException;
    import android.util.Log;


    //Your method you are sending the email from
    public void sendEmail() {
          //Alternate way of instantiating
          //SendGrid sendGrid = new SendGrid(SENDGRID_USERNAME,SENDGRID_PASSWORD);

          //Instantiate the object using your API key String
          SendGrid sendgrid = new SendGrid('YOUR_SENDGRID_API_KEY');

          SendGrid.Email email = new SendGrid.Email();
          email.addTo("example@example.com");
          email.setFrom("other@example.com");
          email.setSubject("Hello World");
          email.setText("My first email with SendGrid Java!");

          try {
               SendGrid.Response response = sendgrid.send(email);
          }
          catch (SendGridException e) {
               Log.e("sendError", "Error sending email");
          }
      }