I'm writing an Android application that allows a call and response between two devices. I'm currently using sendMultipartTextMessage to send a message longer than 160 characters. However the message received is not the message I sent.
String response = "abcd abcd abcd abcdabcd abcd abcd abcd abcd...to 300 chars";
Log.i("response",response);
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(response);
for (String part : parts) {
Log.i("part",part);
}
sms.sendTextMessage(sender, null, "This should be normal", null, null);
sms.sendMultipartTextMessage(sender, null, parts, null, null);
The Log.i runs as expected and outputs the message in parts. The sendTextMessage also sends the correct SMS to my partner emulator. However, the parts sent by sendMultipartTextMessage all come back oddly translated. For example the above response would be received as "BEGIABEGIABEGIABEGIA..." and so on with a few minor variations for spaces and numbers.
What is causing sendMultipartTextMessage to garble the SMS?
Its a bug in the platform: see http://code.google.com/p/android/issues/detail?id=13737. It might be limited to the simulator, so try it on a real device.
sendMultipartTextMessage method does not work correctly when you run your android application from any simulator.
so you need to test your android application on actual android smart phone. one more thing to consider is always pass null as third second argument (string containing phone number of sender) while sending SMS otherwise code will not sms.
i hope this will help you.
Related
When sending a push notification through GCM (switching to FCM soon) to an Android device, how can I localize numbers that appear in the message title/body based on the language of the phone?
Example Message:
John Doe 137
If the device language is set to Arabic the numbers should localize
Localized Message
John Doe ١٣٧
Since I don't know the users device language when sending the notification, how can I localize the number when the message is received? The onMessageReceived callback does not execute unless the application is running in the foreground, so I can not perform a string replacement on the numbers there.
For context Below is an example of the gcmNotification JSON I'm sending to GCM from my services which is taking advantage of some of the other localization params the payload allows you to use.
"gcmNotification": {
"title_loc_key": "some_title_key",
"title_loc_args": "[\"john\", \"Doe\", 137]",
"icon": "TheIcon",
"body_loc_key": "some_key",
"sound": "somesound",
"color": "Blue",
"collapse_key": "somekey",
}
In general you don't try. Arabic numerals (the normal 0-9) are well understood. If you want to insist on trying, you can do it client side with a string replace. Or server side by posting your locale to it and letting the server translate before sending down.
To solve the issue, I ended up creating just a helper class with a method to handle the conversion. I run the message text through it and it returns the translated values. It has worked well for me so far.
public static class NumberHelper
{
public static string ConvertToArabicNumbers(this string input)
{
return input.Replace('0', '\u0660')
.Replace('1', '\u0661')
.Replace('2', '\u0662')
.Replace('3', '\u0663')
.Replace('4', '\u0664')
.Replace('5', '\u0665')
.Replace('6', '\u0666')
.Replace('7', '\u0667')
.Replace('8', '\u0668')
.Replace('9', '\u0669')
.Replace('.', '\u066B');
}
}
My question for you today is "How to reply to an email using windows vbscript." (Gmail) That may not be the best explanation...
WAIT, I already know how to SEND an email (to my phone through phonenumber#txt.att.net) using VBScript, but I want to reply to a text. I have a system that alerts my phone when an action is performed on my computer (through VBScript) but this keeps happening. It's as if I receive the message from a different address each and every time.
So, is there any way to make it so I receive the text from the same recipient each time? Currently, the "phone" number of the sender started at 1410200500 and counts up every time I send it using this vbs code.
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "myemail#gmail.com"
oMsg.To = "myphonenumber#txt.att.net"
oMsg.TextBody = "ALERTMSG"
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport") = 465
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl") = True
oConf.Fields(schema & "sendusername") = "myemail#gmail.com"
oConf.Fields(schema & "sendpassword") = "supersecretpassword"
oConf.Fields.Update
oMsg.Send
Everything works except for the issue of the sender being different each time.
Please help
Edit: I have found that this is unavoidable, thanks to everyone that helped!
There is nothing wrong with your VBScript or the CDO configuration.
The value assigned to the Sender by the SMS Middleware that takes the e-mail and forwards it to an SMS service is outside your control. The only option you have is to contact your SMS provider but I wouldn't suggest they will change how this works.
In fact in this Video at 0:40 it states;
"the number that appears on your recipients phone or device may not be your actual phone number, but they will see the name, subject and e-mail address you used to send the text message."
Useful Links
Send email as text message (AT&T Support)
My code receive data on my Android phone from Arduino via USB host.
The data (in form of bytes) is transformed to String Output, I write code in the method updateReceivedData(byte[]) that checks if the data contains "Warning" word, to send message containing the warning data
I try to make counter to make delay between sending messages in case of continuous warning received data, then I would to reset the counter if there is no warning message
My problem is that the counter reset every time and continue sending message without making delay.
I think the solution is by making delay while The String output is completed, then check on it, but I don't know how?
private void updateReceivedData(byte[] data) throws UnsupportedEncodingException {
String Output = new String(data);
if(Output.contains("Warning")){
if (warncounter==0){
Toast.makeText(getBaseContext(), "Warning message sent", Toast.LENGTH_SHORT).show();
SmsManager.getDefault().sendTextMessage(number, null, Output, null, null);
}
warncounter++;
if(warncounter==52) warncounter=0;
}
else warncounter=0;
mDumpTextView.append(Output);
mScrollView.smoothScrollTo(0, mDumpTextView.getBottom());
}
To make an approach for finding the problem, I try this code
private void updateReceivedData(byte[] data) throws UnsupportedEncodingException {
String Output = new String(data);
if(Output.contains("Warning")){
SmsManager.getDefault().sendTextMessage(number, null, Output, null, null);
}
}
mDumpTextView.append(Output);
mScrollView.smoothScrollTo(0, mDumpTextView.getBottom());
}
In the second code, I let all received data contain warning, the result is that the first message contains the whole output string, but after the first, all received messages are trimmed (maybe due to the data was not completely transformed to string before start sending string)
Note: The data are sent from Arduino every one second, and the data in the scrollview text appears correctly 100% (this indicates that the data was transformed to String but maybe the problem is that it takes time)
So please help or make suggestions
I found the problem
The problem is that android cannot read the whole data sent from arduino (using Serial.print ()) by a single bulktransfer () function call, so I make the bulktransfer () (or read) in a while loop, then I check on each Sting sent by arduino by building a String when each new line ("\n") is detected in the readed data
When I use ContentResolver.query(Calls.CONTENT_URI, null, Calls._ID = 'call ID here', null,null); the text (logtype=100 OR logtype=500) is added to the query.
what do 100 and 500 mean ?
I suppose you have a Samsung Android device. Look here:
100 is for voice calls.
SMS are duplicated as Calls(Samsung galaxy S II)
I used Receiver to capture incoming SMS. But come across this problem:
When sending Chinese SMS(你好,for example), the receiver is called correctly.
After extracting the pdus, building the SmsMessage,the SmsMessage.getMessageBody() returns incorrect decoding of USC2, which I assume.
In the above example:
你好 is the only userData, which is encoded to 0x4F60 0x590d in the pdus.I saw this in debugger.However,the getMessageBody() return a String, who content is \u004f \u00a1 \u0065 \u006a.
I read the source code, but still cannot understand why.
Any help?Thanks.
Did you set the encoding ?
http://developer.android.com/reference/android/telephony/SmsMessage.html