google cloud endpoints - How to import Sendgrid in android studio -
i use sendgrid send emails google endpoint project, developing in android studio. problem can't find example of how import sendgrid library, tried , other variants:
compile 'com.sendgrid:1.0.6'
where 1.0.6 latest version? find
the answer cfl doesn't work newest version of android studio. using send-grid java dependency clashes various dependencies native android studio. thankfully found forked version made dany santiago. in example, uses user name , password instantiate sendgrid object if have api key, can use instead avoid saving account information on device. add dependencies in build.gradle (app) of android studio project:
compile 'com.github.danysantiago:sendgrid-android:1'
do not use sendgrid-java android studio, not work. more information, here link https://github.com/danysantiago/sendgrid-android
also, don't need use example used in link. if have api key sendgrid, sample code work fine:
//might need other imports import com.sendgrid.sendgrid; import com.sendgrid.sendgridexception; import android.util.log; //your method sending email public void sendemail() { //alternate way of instantiating //sendgrid sendgrid = new sendgrid(sendgrid_username,sendgrid_password); //instantiate object using 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 sendgrid java!"); try { sendgrid.response response = sendgrid.send(email); } catch (sendgridexception e) { log.e("senderror", "error sending email"); } }
Comments
Post a Comment