How to display properly formatted E-mail in TextView in android - android

I am working on an E-mail Application where I have to send and receive and also have to display email in TextView when ever user wants to read it
This is the feed I am getting from API :-
{
"messages":
[{"id":"136902",
"from":"Akash",
"email":"akash#email.com",
"subject":"mail App!!",
"message":"Hi Devraj,\n\n \n\nKindly provide sabmail apk for google play store.\n\n \n\nRegards,\n\nAkash",
"date":"1448870780",
"userid":"75",
"recipients":"devraj#mail.com ",
"status":"0",
"isread":"1",
"priority":"3",
"size":"3057"}
]}
I am taking the "message" tag and displaying it in TextView. It looks like this
Hi Devraj,Kindly provide mail apk for google play store.Regards,Akash,
But, I want it to be look like this,
Hi Devraj,
Kindly provide mail apk for google play store.
Regards,
Akash,
How can I do achieve this.
This is the way I am setting it in TextView
String msg = messageDisc.getMessage();
Spanned sp = Html.fromHtml(msg);
emailText.setText(sp);
emailText.setMovementMethod(LinkMovementMethod.getInstance());
Please let me know what mistake I am doing here.

Try to replace: \n with <br>.
String msg = messageDisc.getMessage();
msg = msg.replace("\n", "<br>");
Spanned sp = Html.fromHtml(msg);

Supply android:maxLines="<any number>" to the TextView. So that \n will work.

first parse the json data and stored it into a different String.
Then set the String object to the edittext by seperating it with a \n line.
eg: emailText.setText(sp+"" +\n+""+obj);

Related

Avoid malicious code to be sent to FirebaseDatabase via chat on Android

I'm working on an application that has a chat implemented with FirebaseDatabase, like the one shown in this codelab: https://codelabs.developers.google.com/codelabs/firebase-android/#0
The problem is: the user is free to send anything on chat, is it possible to block code like HTML or JS to be sent, to avoid security problems, or this can be treated only when reading messages sent?
On the user side you can remove HTML tags when submiting the message:
str = str.replaceAll("<(.*?)\\>", " ");//Removes all items in brackets
str = str.replaceAll("<(.*?)\\\n", " ");//Must be undeneath
str = str.replaceFirst("(.*?)\\>"," ");//Removes any connected item to the last bracket
str = str.replaceAll(" ", " ");
str = str.replaceAll("&", " ");
Also by default, most HTML tags won't be executed in your TextView unless you used fromHtml function.
I've done adding this method to the text sent via chat:
private fun removeHTMLCode(text: String?) = text?.replace("<[^>]*>".toRegex(), "")?.trim()

Set paper size A4 while printing from google cloud print API

I have integrated Google cloud printing API in android application. I am printing image from GCP. Everything is working fine. I want to set paper size using API. Is that feasible?
Currently i am sending following data :
**URL :**...cloudprint/submit
**Param :**
printerid
file
title
contentType
As per google document, we can use ticket param for that. not sure what to send in this key.
Any help appreciated.
We need to pass the A4 specifications to the G.C.Printer.
You need to pass ticket in the path parameter along with printerid, file, title, contentType and should look like this:
ticket : {"version":"1.0","print":{"media_size":{"width_microns":210000,"height_microns":297000,"is_continuous_feed":false,"vendor_id":"ISO_A4"}}}
(^above are the specs of A4 media size)
Your params should look like this:
printerid : <printerid>
content: <content>
title : <title>
contentType: <contentType>
ticket : {"version":"1.0","print":{"media_size":{"width_microns":210000,"height_microns":297000,"is_continuous_feed":false,"vendor_id":"ISO_A4"}}}
Also, this works perfectly for GCP version 2.0
Ticket params is basically the settings we send to G.C.Printer and by default, it sends media type as "NA_LETTER". We can override the default settings by sending the ticket parameter to trigger the print.
GCP parses the ticket and uses the key value accordingly. If any key is wrong, it throws "unable to parse ticket" error.

What is a Page ID for the place field in Post Facebook Graph API?

I am having trouble while trying to post a message on the current end-user Facebook wall with my Android Application.
So far :
The user is logged in with all the required permissions, especially
the publish_actions permission ;
I am using the last version of Facebook SDK 3.x & Graph API v2 as of May 2014
Post to wall works now as of EDIT 2, but there are issues with
privacy settings : post cannot be seen by anyone not even the
recipient who is tagged in the post ! See EDIT 2 for more details
Here is the documentation for posting a message on the user wall :
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed (go to Publishing)
Regarding the message that needs to be posted on the user' wall, I need to tag some friends that were previously selected by the user.
But to use the tag field I need to use the place field.
The documentation says :
Name: tags
Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place.
Type: csv[string]
Name: place
Page ID of a location associated with this post.
Type: string
What is location page ID ? How do I get it ?
Oddly enough, in my specefic case, I am offering the possibilty to the user to share is upcoming travel on Facebook.
More oddly enough, this travel is defined by dates and a destination (name of destination + latitude & longitude). The user has the possibility to also share this travel to his friends that are located in his travel's destination hence the need to tag his friends to the wall post.
[EDIT 1]
After looking into #Tobi solutions, I managed to post a message on the end-user wall (in my case me, since I am the developper).
So far : the message is correctly displayed with a friend tagged (a dummy account I use for tests purpouses) and there is also the place : Paris, France.
Using the following search query (thanks #Tobi) search?q=Paris,France&type=place I can get the ID of Paris, France.
Since I did not code the part to retrieve the Place ID it put it manually in the code for the sake of testing the feature first.
[END OF EDIT 1]
[EDIT 2]
I noticed I forgot to add the part with the privacy values to my args Bundle. But it did not change a damn thing : my post is only visible to me alone.
Going to my Facebook wall, here is what I get :
Hovering the public parameters of the posts (a padlock icon) says "All tagged persons".
Clicking on the icon shows the list of settings with only "Only me" selected.
Why "only me" even though I specifically said me + my dummy account in the request parameters ?
Even weirder : changing the property of the publication parameters to "customized" with my dummy account does not change a damn thing as well. Just why ? Facebook is really getting on my nerve...
For the rest, the message content is correctly displayed and the related place is the good one. At least a got that correctly. But still, I just don't get the rest ...
[END OF EDIT 2]
So here is the updated code :
if (this.session != null && this.session.isOpened()) {
final Bundle args = new Bundle();
if (this.selectedContacts.isEmpty() == false) {
args.putString("message", message);
args.putString("place", "170558129707208"); //manually added Paris, France ID
String tags = "";
//here I made some modifications regarding the tags so that is built correctly
for (int it = 0; it < this.selectedContacts.size(); it++) {
final String name = this.selectedContacts.get(it).toString();
final String friendID = String.valueOf(getIdFromName(name)); // returns an int
if (it == this.selectedContacts.size())
tags += friendID;
else
tags += friendID + ",";
}
// Forgot to add privacy values to bundle !
final JSONObject privacyValues = new JSONObject(); //not android JSON, but JSON-Simple lib
privacyValues.put("value", "CUSTOM");
String allow = this.currentUser.getId() + "," + tags;
privacyValues.put("allow", allow); // to limit the visibility of this post
args.putString("privacy", privacyValues.toJSONString()); //forgot that one...
final Request shareTravelRequest = new Request(this.session, this.currentUser.getID() + "/feed",
args, HttpMethod.POST, new Request.Callback() {
public final void onCompleted(final Response response) {
//TODO
}
}
);
final Response response = shareTravelRequest.executeAndWait();
if (response.getError() == null) // in this case, no error occurred
return true;
else {
this.lastErrorMessage = response.getError().getErrorMessage();
Log.e("Something went wrong while posting Facebook message", this.lastErrorMessage);
Log.e("Error type is", response.getError().getErrorType());
Log.e("Error code is", String.valueOf(response.getError().getErrorCode()));
return false;
}
}
}
Unfortunately I must have mistaken somewhere because although the post does appear on my Facebook wall with my dummy account tagged and with the correct link to the place, my dummy account cannot see the post.
I tried creating manually the same post on my Facebook wall by using the following settings :
First I supplied a message
Second I supplied a place
Third I tagged my dummy account
Four I choose who can see this post : me and my dummy account
And finally, I post the message.
In this case, my dummy account sees the post both on its wall and on my wall.
So I would like to know what parameters I must get wrong because there is not much parameters and I just don't see why.
Thanks !
You can either use the Search and use the type place (https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search), or, if you have positioning date, use an FQL query on the place table (https://developers.facebook.com/docs/reference/fql/place/) as described here: Facebook places: order results by distance
Use two test accounts made via Facebook Developer App settings and not a dummy account that breaks TOS. Since you request publish_actions you probably didn't submit the app for review. Unless your dummy account is a developer/tester in roles as well (which is breaking the TOS again) then your dummy account will not be able to see the post.
Only developers and testers of an unpublished application can see posts made by that application.

Getting Gender of People in Google + in android

I have been trying to create an android app where I could Use Google + login. When I try to get data from the Google +, I am getting Gender as Male ("0") for all Google + users despite their Gender being Female in the actual Google + page.
Is this a bug from Google plus, or Is their anything like permission needed ?
^^^^^^^^Edit^^^^^^^^^^^^^^
I called mPlusClient.connect();
and then in the onConnected() I called mPlusClient.loadVisiblePeople(this, null);
In the onPeopleLoaded method I called personBuffer.get(i).getGender().
I am getting the gender as 0.
Note: I am getting the Display name , Profile Image in the same way as getting Gender and It is working fine.
Finally it worked. Need to add permissions to access gender and other details of people within the circle. The code snippet is:
mPlusClient = new PlusClient.Builder(this, this, this).setActions(
"http://schemas.google.com/AddActivity",
"http://schemas.google.com/BuyActivity").setScopes(Scopes.PLUS_LOGIN,Scopes.PLUS_PROFILE).build();

How to email bold text from android application?

I am using this code for mailing from android application.
GmailSender sender = new GmailSender("android.tech1q2#gmail.com","password");
sender.sendMail("Thank you state",
"<u>Jignesh</u><b>Jignesh</b>",
"android.tech1q2#gmail.com",
"jansodariya#gmail.com");
but I am not getting words underline and bold then what should I do for this please help me
I want to send mail as Html.
Thanks!
try this
sender.sendMail("Thank you state"
,Html.fromHtml("<u>Jignesh</u><b>Jignesh</b>"),
"android.tech1q2#gmail.com"
"jansodariya#gmail.com"));

Categories

Resources