Sorry for the confusing title. I have an app and I want my users to send me feedback. I need something thats not too fancy, just a text box where the user and can type and button to send a message to an email account I have set up for feedback. I want the user to be able to do this without using any of their email accounts or other account. Can I use something like JSON to send a feedback?
3 Answers
You can allow the users to send the feedback with basic email validation checkup. This part of code runs on API level 8 and above. Onclick of send button just do this basic email validation
public boolean checkEmail(String email) {
try {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
} catch (Exception e) {
Logging.e(TAG, "Email Validation", "Error: "+e.getMessage(),e);
}
return false;
}
If the validation returns true. Then get the entered email id and the text content from the edit text and frame a post url and check for the response if it is HttpStatus.SC_OK.if it returns ok then from post execute call a method in your activity using a listener to show a popup that the feedback has been sent successfully. To post the url and to check for the response.Frame the url in do in background and pass the url to this method some wherei n your Utils class to return the response.
public static boolean sendRequestOnly(String url) {
DefaultHttpClient client = returnHttpClient();
HttpGet getRequest = new HttpGet(url);
try {
HttpResponse resp = client.execute(getRequest);
final int statusCode = resp.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
Logging.d("ClassName", "Retreive response", "Status Code "
+ statusCode + " for URL " + url);
return true;
} else {
return false;
}
} catch (IOException e) {
getRequest.abort();
}
return false;
}

- 535
- 4
- 12
-
I think I will go with this. This helpful. I just have a few clarifications. I just want it be able to send it my email address. So in the checkEmail method, I would pass in a string with my email address? like String email = "mymail@gmail.com" ?? – Ra Ghazi Sep 08 '13 at 15:41
-
Also can you clarify what URL I am passing in to sendRequestOnly method? I didn't quite understand what you meant by "frame a post url" also where exactly do I send the message to my email? – Ra Ghazi Sep 08 '13 at 15:43
-
checkEmail Method will accept the mail id user has entered.That mail id is validated. You will be framing a Url in which you will be sending the email id text content and other parameters .This url wil be sent to sendRequestOnly method. – khubaib Sep 08 '13 at 15:49
-
What do you mean by mail id? its the email address right? I am still a little confused on the framing a URL part? I will create one string that has the email id and text content and call the sendRequestOnly method. – Ra Ghazi Sep 08 '13 at 16:01
-
To frame a url have this in a method. The feedback sent has to reach you right?
String url = "https://blablabla.net/";
StringBuilder sbUrl = new StringBuilder("feedback.jsp?email=");
sbUrl.append(emailId);
sbUrl.append("&content=");
sbUrl.append(textContent);
sbUrl.append("&subject=");
sbUrl.append(subject);
sbUrl.append("&os_version=");
sbUrl.append(OptimumConstants.OS_VERSION);
//if you want the userId.Person who has sent you the feedback etc sbUrl.append("&user_id="); sbUrl.append(settings.getString( SomeConstants.LOGGED_IN_USERNAME, "")); //here you can append of there are any other request urlparams like device id,device type,os version etc only if you want all this info sbUrl.append("&"+Utils.FewOtherRLParams); url += sbUrl.toString();
boolean resp= Utils.sendRequestOnly(url);
return resp;

- 535
- 4
- 12
-
Thank you very much for your support. For string url what kind of website goes in there? Can it be String url = "myemail@gmail.com" and what do I put in the "feedback.jsp?" whats is feedback.jsp? Should I implement that? – Ra Ghazi Sep 08 '13 at 16:39