我目前正在使用我的应用尝试邀请其他人加入以测试该应用。用户将输入访客的电子邮件地址,他们应该收到一封电子邮件以作为访客加入。出于某种原因,用户没有收到电子邮件。
编程和Android工作室非常新,所以有人可以帮助我。 我已经放了一个xml的图像来向你展示它的外观。
public class ClientInfo extends AsyncTask<Void, Void, Void> {
private static final String TAG = "ClientInfo";
private static final String url = "https://"+ BuildConfig.PORTAL_HOSTNAME+"/api3/im/%s/invite";
private final String emailaddress;
private final Context context;
private final String deviceId;
public ClientInfo(Context context, String emailaddress) {
this.deviceId = SaltIMApplication.getDeviceId(context);
this.emailaddress = emailaddress;
this.context = context;
}
protected String readResponse(HttpPost post) throws Exception {
return Utils.readResponse(Utils.getHttpClient().execute(post));
}
protected Void doInBackground(Void... voids) {
Log.i(TAG, "Invite ---- Send invite");
String path = String.format(url, this.deviceId);
String response = "";
Log.i(TAG, "Invite ---- Path is:" + path);
try {
Log.i(TAG, "Invite ---- Post is: " + (Utils.createJsonPost(path, createBody())).toString());
response = readResponse(Utils.createJsonPost(path, createBody()));
} catch (Exception e) {
Log.i(TAG, "Invite ---- Response from the invite - " + e.getMessage());
}
if (!response.equals("")) {
try {
JSONObject jsonObject = new JSONObject(response);
String s = jsonObject.toString();
Log.i(TAG, "Invite ---- Response: " + s);
} catch (JSONException e) {
Log.i(TAG, "Invite ---- Response: JSONException");
e.printStackTrace();
}
}
return null;
}
private StringEntity createBody() throws JSONException, UnsupportedEncodingException {
JSONObject jsonRequest = new JSONObject();
jsonRequest.put("email", emailaddress);
jsonRequest.put("secret", BuildConfig.SHARED_SECRET);
Log.i(TAG, "Invite ---- JsonObject is: " +jsonRequest);
Log.i(TAG, "Invite ---- Sending invite");
return new StringEntity(jsonRequest.toString());
}
}
这是我的活动
public class ClientInviteActivity extends AppCompatActivity {
private static final String TAG = "ClientInviteActivity";
@InjectView(R.id.enterEmail)
EditText emailEntry;
@InjectView(R.id.inviteButton)
ImageButton inviteButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.client_invite);
ButterKnife.inject(this);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle("Guest Invite");
}
@OnClick(R.id.inviteButton)
public void onClick(){
Log.i(TAG, "Invite - we are going to send an invite to " + emailEntry.getText().toString());
String email = emailEntry.getText().toString();
ClientInfo clientInfo = new ClientInfo(this, email);
clientInfo.execute();
}
}