How android can parse mailto url containing Japanese or Chinese characters - android

i've tried to parse a mailto url which contains Japanese or Chinese characters by using MailTo.parse(url) but it return null.
it's ok with English characters. How do I resolve that?
There's my code and logcat:
try {
url = URLDecoder.decode(url,"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(TAG, "url: " + url);
MailTo mt = MailTo.parse(url);
Log.d(TAG, "body: " + mt.getBody());
Log.d(TAG, "subject: " + mt.getSubject());
07-12 12:50:34.861: D/Fbaku(9484): url: mailto:?subject=幕末の時代を生き抜け!&body=iPhoneとiPod Touch対応の風雲幕末史を一緒にやりませんか?
07-12 12:50:34.861: D/Fbaku(9484): subject: null
07-12 12:50:34.861: D/Fbaku(9484): body: null
Edit: sorry, my mailto url contains a link in body like this: https://stackoverflow.com/posts/17607307
So MailTo.parse(url).getBody() and MailTo.parse(url).getSubject() return NULL
How can i fix it?

try by using toString() method
so change
Log.d(TAG, "body: " + mt.getBody());
Log.d(TAG, "subject: " + mt.getSubject());
to
Log.d(TAG, "body: " + mt.getBody().toString());
Log.d(TAG, "subject: " + mt.getSubject().toString());

Related

SMS with GoogleMaps link is not sent

I work with sending SMS with the GoogleMaps link, but in some cases, the phone does not send, I can not know the reason, other links are sent normally.
Here is the image of the message:
I would like some help in resolving this issue. And, importantly, The idea of using SMS is to not need the internet.
Here is the code I use for generation:
String uri = "http://maps.google.com/maps?q=" + lat + "," + lng;
if (!preferences.getNumber(activity).equals("")) {
smsBody.append(Uri.parse(uri));
String phone1 = preferences.getNumber(activity);
try {
smsManager.sendTextMessage(phone1, null, msgASerEnviada, null, null);
smsManager.sendTextMessage(phone1, null, smsBody.toString(), null, null);//mensagem com o link
Toast.makeText(activity, "Sent to " + phone1, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, "Something wrong", Toast.LENGTH_SHORT);
}
}
resolved by removing the http: //

Gear SDK SAFileTransfer FILE_IO error

I'm trying to send file from Android host to Samsung Gear device using Samsung Mobile SDK no matter how had I try, always get FILE_IO error.
I was trying all available permissions (on both sides).
Could anyone send me any hint?
Android side:
String filename = "file:///storage/emulated/0/Download/TestRecipe2-25.zip";
if (mGuruAgentService != null) mGuruAgentService.sendFile(filename);
public int sendFile(String fileName) {
if (mFileTransfer == null)
registerForFileTransfer();
if (mFileTransfer != null) {
try {
Log.i(TAG, "Sending file " + fileName);
tx = mFileTransfer.send(mPeerAgent, fileName);
return tx;
} catch (Exception e)
{
Log.i(TAG, "Cannot send file" + e.getMessage());
}
}
return 0;
}
Tizen side:
function fileReceiveInt() {
var newFilePath = "downloads/file.zip";
var receivefilecallback =
{
onreceive: function(transferId, fileName)
{
console.log("Incoming file transfer request form the remote peer agent. transferId: " + transferId + " file name : " + fileName);
try {
gFileTransfer.receiveFile(transferId, newFilePath);
} catch(e) {
console.log("Error Exception, error name : " + e.name + ", error message : " + e.message);
}
},
onprogress: function(transferId, progress)
{
console.log("onprogress transferId: " + transferId + ", progress : " + progress);
},
oncomplete: function(transferId, localPath)
{
console.log("File transfer complete. transferId: " + transferId);
},
onerror: function(errorCode, transferId)
{
console.log("FileReceiveError transferId: " + transferId + " code : " + errorCode);
}
}
try {
console.log('setting recieve interface');
gFileTransfer = SAAgent.getSAFileTransfer();
gFileTransfer.setFileReceiveListener(receivefilecallback);
} catch (err) {
console.log('getSAFileTransfer exception <' + err.name + '> : ' + err.message);
}
}
I will always get onError in tizen with FILE_IO error :(
I was testing gFileTransfer.receiveFile(transferId, ""); for default path, and File:///opt/usr/media/Downloads...
My tizen privileges:
<tizen:privilege name="http://tizen.org/privilege/content.read"/>
<tizen:privilege name="http://developer.samsung.com/privilege/accessoryprotocol"/>
<tizen:privilege name="http://tizen.org/privilege/content.write"/>
<tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>
<tizen:privilege name="http://tizen.org/privilege/filesystem.write"/>
<tizen:privilege name="http://tizen.org/privilege/unlimitedstorage"/>
Thanks in advance for any help.
Change both filepaths and it should work.
Change Android's side to:
String filename = Environment.getExternalStorageDirectory() + "/Download/TestRecipe2-25.zip";
Change Tizen's side to:
var newFilePath = "file:///opt/usr/media/Downloads/file.zip";

Jsoup: How to get Video url?

I am trying to parse video url from html. I am using Jsoup parse to parse it. I want to parse
<meta property="og:video" content="http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true">
from this html. How can i get this content from the above line.
Now my code is:
try {
Connection.Response response = Jsoup
.connect(htmlUrl)
.userAgent(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.timeout(10000).execute();
int statusCode = response.statusCode();
Log.d("TAG", " status code is: " + statusCode);
if (statusCode == 200) {
doc = Jsoup.connect(htmlUrl).timeout(1000 * 100).get();
Log.d("TAG","Document is created : " + doc );
Elements element = doc.select("meta");
for (Element urls : element) {
//System.out.println(urls.text());
Log.d("TAG", " url is: " + urls.attr("property") + " " + urls.attr("og:video"));
}
} else {
System.out.println("received error code : " + statusCode);
}
What should change in my code?
Thank you in advance!
Assuming you are using asynctask/thread for network related operation.
Assuming its the first meta you can do as below
String myhtml ="<meta property="+"og:video" +" "+"content="+"http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true"+">";
Document doc = Jsoup.parse(myhtml);
Element eMETA = doc.select("meta").first();
String s = eMETA.attr("content");
I changed my code as follows:
try {
Connection.Response response = Jsoup
.connect(htmlUrl)
.userAgent(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.timeout(1000000).execute();
int statusCode = response.statusCode();
Log.d("TAG", " status code is: " + statusCode);
if (statusCode == 200) {
doc = Jsoup.connect(htmlUrl).timeout(1000 * 1000).get();
Elements meta = doc.select("meta[property=og:video]");
for (Element src : meta) {
if (src.tagName().equals("meta"))
Log.d("TAG", " content: " + src.attr("content"));
else
Log.d("TAG", src.tagName());
}
} else {
System.out.println("received error code : " + statusCode);
}
} catch (IOException e) {
Log.d("TAG", " Exception " + e);
e.printStackTrace();
}

How to send email with html table output in email

I am working on ArrayList, i want to send email type of html format with arraylist content,
i am trying to write array content in BufferedWriter Like..
mOrderList = db.getOrderList();
// getting all arrayList content
for (int i = 0; i < mOrderList.size(); i++) {
no = mOrderList.get(i).getId();
itemName = mOrderList.get(i).getOrderItemName();
unit = mOrderList.get(i).getOrderUnit();
qty = mOrderList.get(i).getOrderQTY();
rate = mOrderList.get(i).getOrderRate();
amt = mOrderList.get(i).getOrderAmount();
try {
mbufferWriter =new BufferedWriter(new FileWriter("/data/data/com.sample.category/abc.txt"));
mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body> <table>"
+ "<tr><th>Item No</th>" + "<th>Item Name</th>"
+ "<th>Unit</th>" + "<th>QTY</th>" + "<th>Item Rate</th>"
+ "<th>Amount</th></tr>");
mbufferWriter.append("<tr><td>" +no+"</td>");
mbufferWriter.append("<td>"+itemName+ "<td>");
mbufferWriter.append("<td>"+unit+ "<td>");
mbufferWriter.append("<td>"+qty+ "<td>");
mbufferWriter.append("<td>"+rate+ "<td>");
mbufferWriter.append("<td>"+amt+ "<td></tr>");
mbufferWriter.append("</body></table></html>");
mbufferWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//for
and trying to send an email like this but it gives error...
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "abc#gmail.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "sample email sending");
i.putExtra(Intent.EXTRA_TEXT,Html.toHtml((Spanned) mbufferWriter));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
// startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EmailActivity.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
can any one help me fix this problem ..
Thanks in advance..
Html.toHtml doesn't support <table>. It only supports basic tags like <b><u><i>...
Use a pre tag to create a table:
mbufferWriter.write("<html><h4>Customer Order List</h4>" + "<body>" +
"<pre> " +
" Item No Item Name Unit QTY Item Rate Amount" +
"</pre>");

FB.api('/me') always giving error code:2500 in phonegap android

I am using facebook plugin to login and logout a user, which are working fine. The problem is when I request for the logged in user details using the function FB.api('/me'), it always gives the following error:
{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}
I used the debug mode to check PluginResult(pr) and JSONObject of the response. JSONObject contains the user information, which I required, I dont get where I am doing wrong.
Plz help......
MY CODE:
function login() {
FB.login(function(response) {
if (response.session) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + JSON.stringify(response) + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email,user_likes'});
}
function logout() {
FB.logout(function(response) {
console.log(localStorage.getItem("user_fb_log_status"));
localStorage.setItem("user_fb_log_status","LOGGED_OUT");
alert('logged out');
});
}
The above code is working fine to login and logout the user. Below is the code i used to get the user details,
function me() {
FB.api('/me', { fields: 'id, name, picture' }, function(response) {
if (response.error) {
alert(JSON.stringify(response.error));
} else {
var data = document.getElementById('data');
fdata=response.data;
console.log("fdata: "+fdata);
response.data.forEach(function(item) {
var d = document.createElement('div');
d.innerHTML = "<img src="+item.picture+"/>"+item.name;
data.appendChild(d);
});
}
});
}
You need access token to retrieve more details than basic user information. Check that whether you have correct access token in Debug Tool to and ensure that you have all require permissions set permission.
Problem solved after changing the "session" in 'getResponse' method in ConnectPlugin to "authResponse"
FB.api method is working fine for me to get the user details and post a feed to the facebook after I change the following method in ConnectPlugin.java as following.
public JSONObject getResponse() {
String response = "{" + "\"status\": \""
+ (facebook.isSessionValid() ? "connected" : "unknown") + "\","
+
// "\"session\": {" + "\"access_token\": \""
// + facebook.getAccessToken() + "\"," + "\"expires\": \""
// + facebook.getAccessExpires() + "\","
// + "\"session_key\": true," + "\"sig\": \"...\","
// + "\"uid\": \"" + this.userId + "\"" +
"\"authResponse\": {" +
"\"accessToken\": \"" + facebook.getAccessToken() + "\"," +
"\"expiresIn\": \"" + facebook.getAccessExpires() + "\"," +
"\"session_key\": true," +
"\"sig\": \"...\"," +
"\"userId\": \"" + this.userId + "\"" +
"}" + "}";
try {
return new JSONObject(response);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new JSONObject();
}

Categories

Resources