Android passing multiple numbers to SMS intent - android

I am getting different numbers from Contacts and passing them to SMS application. I am using the following:
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:"+numbers) ); //numbers separated with ;
intent.putExtra( "sms_body", body );
startActivity( intent );
The problem is if I separate numbers with ' ; ', it does not work on Galaxy S but works on others like HTC, Samsung Gio etc... On Galaxy S, it works if I separate numbers with comma ' , '. So how to resolve this issue?

Normally using a semicolon (';') is the right choice to separate phone numbers. So you should use this. It might be due to vendor specific adjustments or custom vendor applications that it does not work on Galaxy S for example.
I would propse to use semicolon everywhere except for Samsung devices. You unfortunately have to do this ugly vendor specific decision within your source code.
String separator = "; ";
if(android.os.Build.MANUFACTURER.contains("Samsung")){
separator = ", ";
}
// set the numbers string with the use of 'separator'

Note that the solution provided (using the os.Build.MANUFACTURER string) does not work in all situations!
I have several users that use a Samsung device which run's a Cyanogenmod version of Android. In this situation the MANUFACTURER string contains "Samsung", but the separator should be a ";" instead of the ",". I did not find a solution for this issue yet...

Related

SMS body text for html with % for percent sign crashes android app

Whenever I put a % in the body of my sms html link like:
sms (? or & separating depending on ios android) :
a href="sms:555555555?body=Hello123 % testing!"target="_parent">
Click /a
It crashes my messaging app on android, but on iOS it's fine. I tried to encode it as well, but that didn't seem to work. Any clue on how to escape this?
EDIT: This only happens with Google Messages, Samsung Messages is ok
try to write with symbol like ©<p>Copyright ©</p>
Try to encode percent like
a href="sms:555555555?body=Hello123 %25 testing!"target="_parent">
I had the same issue and spent a lot of time but solution was pretty simple.
Need to replace '%' with one of these:
percent sign variations
SMS body encoding function:
function encodeSMSText(text) {
const updatedText = text.replace(/%/g, String.fromCharCode(0xFF05));
return encodeURIComponent(updatedText)
.replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}

how to send SMS in Flash Air for Android

I am trying build an sms based application in AIR (Flash)
Got this code from an old link
str = "sms:1-415-555-1212";
var urlReq:URLReq = new URLRequest(str);
navigateToURL(urlReq);
but this one is 5 years old and lot has change and even Flash is now Animate CC
so can anyone help me in this
5 years, but still nothing changed - your code will work on modern devices.
You can use the URL with sms: - This is supported in all mobile OS:
private function sendSMS(phone:string):void
{
navigateToURL(new URLRequest("sms:" + phone));
}
For example:
navigateToURL(new URLRequest("sms:+00133234534"));
Bonus Tip!
Send a phone call: navigateToURL(new URLRequest("tel:" + phone));
Send an email: navigateToURL(new URLRequest("mailto:" + email));

Titanium: Show and Create Contact Intent

I was trying to export contacts from my application to the native android contacts.
I found the following solution here on this site: Titanium: How to add Contact in Phone book in Android?.
And it kinda works. The intent gets started. Only problem is, that android does not recognize most of the Extras i put in. So almost every field is blank. It does not matter if I replace contactModel with a simple String, the result is the same.
So i was wondering if the keys are simply wrong, but there seems no proper documentation on appcelerator. Probably something has changed over the past years or I am just missing something. Does anybody know how to do it the right way.
Code Snippet:
if (OS_ANDROID) {
var intent = Ti.Android.createIntent({
action : 'com.android.contacts.action.SHOW_OR_CREATE_CONTACT',
data : 'mailto:' + contactModel.get('contact_first_name') + ' ' + contactModel.get('contact_last_name')
});
intent.putExtra('email', contactModel.get('contact_email'));
intent.putExtra('email_type', 'Work');
intent.putExtra('phone', contactModel.get('contact_mobile_number'));
intent.putExtra('phone_type', 'mobile');
intent.putExtra('name', contactModel.get('contact_first_name') + ' ' + contactModel.get('contact_last_name') );
intent.putExtra('address', addressModel.get('address_street') + ", " + addressModel.get('address_city'));
intent.putExtra('address_type', 'Work');
Ti.Android.currentActivity.startActivity(intent);
}
Thx in advance. :)
The first parameter of putExtra() also accepts one of the constants Ti.Android.... So instead of email you would probably have to use Ti.Android.EXTRA_EMAIL.
I think you can find quite a lot in the docs, e.g. here:
EXTRA constant properties in Ti docs
EXTRA constants in Android docs
Android Intents in Ti docs

how to send SMS or make a phone call from a samsung gear s app

i am trying to find a way to send SMS and make a phone call from a samsung gear s app.
the documentation is mostly missing and searching for this did not lead to much findings.
has anybody worked with that? is it at all possible?
as an alternative, if the app cannot send SMS or make the call, is it possible to start the default apps (similar to Android intent for SMS/Phone app or iOS openURL).
thanks.
#memical - I have found a workaround to launch message/sms app using the app id.
<p onclick="hackSMS();">Send SMS</p>
<script>
function hackSMS() {
tizen.application.launch("com.samsung.message", function(){console.log ("Launched")});
}
</script>
Remember to add this http://tizen.org/privilege/application.launch priviege in your apps config.xml
Note: I tried other methods also like using exposed tizen platform api's for web apps to launch some predefined app control. But it is working for Call and not for sms.
here is what i find so far:
to make a call from a Gear S app use the following code:
var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/call", "tel:001....");
tizen.application.launchAppControl(appControl, null,
function() {
console.log("ok");
},
function(e)
{
console.log("error: " + e.message);
},
{
onsuccess : function()
{
console.log("ok 2");
},
onfailure : function(er)
{
console.log("error 2: " + er.message);
}
});
sending SMS is not possible at this time.
There is no messaging API implemented on Tizen for wearable devices. You can check it yourself by calling:
console.log(tizen.messaging);
It will return 'undefined'
It means that you can't programmatically send or read an SMS or an email from your wearable device using Tizen messaging API.
To open the app for make a call try this code:
Uri number = Uri.parse("tel:"+telNumber);
Intent openCallIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(openCallIntent);
To make a call:
Uri number = Uri.parse("tel:"+telNumber);
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(number);
startActivity(callIntent);
To send an sms:
Intent sendSmsIntent = new Intent(Intent.ACTION_VIEW);
sendSmsIntent.setType("vnd.android-dir/mms-sms");
sendSmsIntent.putExtra("address", telNumber);
sendSmsIntent.putExtra("sms_body","Whatever you want");
startActivity(sendSmsIntent);
Similar questions to this one are already answered in stackoverflow
Try this which is very simple as compare to using the platform APIs.
http://www.w3.org/TR/mwabp/#bp-interaction-uri-schemes
The most broadly supported scheme is tel: as described in RFC3966
[RFC3966]. Code such as the following can be used to enable
"Click-to-Call":
[PHONE-NUMBER]
Note that [PHONE-NUMBER] should always be entered using the full
international prefix (e.g. +1-201-555-0111) to ensure that it works
outside of its home country.
Similarly RFC5724 [RFC5724] can be used to send a GSM SMS (text
message) as follows:
[PHONE-NUMBER]
Note that at the time of writing support for this RFC is limited and
device compatibility should be verified before deployment.

Jelly Bean Issue - wifiManager.getConnectionInfo().getSSID() - extra ""

Hi all bug reporting for your information. link
Problem details:
The Code - wifiManager.getConnectionInfo().getSSID()
The above code to returns the current SSID, it is returning the current SSID with extra quotations around it.
For eg. the SSID internet is returned as "internet".
This is only seen on Jelly bean 4.2 using device Nexus 7.
This bug is causing errors in our app as we compare the current SSID with the SSID that we are trying to connect too.
The code wifiManager.getScanResults(); however still returns all SSID's without extra quotation marks.
this is not a bug and behavior is correct as per documentation at http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getSSID()
The so-called bug apparently was in pre 4.2 devices, because they didn't return it with "" enclosure.
Aiden's method looks good to me in the current state of confusion left by Android. However, being theoritically correct would just require
if (ssid.startsWith("\"") && ssid.endsWith("\"")){
ssid = ssid.substring(1, ssid.length()-1);
}
This regular expression is quite neat:
String ssid = wi.getSSID().replaceAll("^\"(.*)\"$", "$1");
Just for the notes
Edit °1 (as per question in the comment):
The issue that OP describes is, that on some devices the SSID returned by getSSID() is enclosed in "" whereas it is not on other devices. E.g. on some devices the SSID is "MY_WIFI" and on others it is MY_WIFI - or spoken in Java code: "\"MY_WIFI\"" and "MY_WIFI".
In order to to unify both results I proposed to remove the " at start and end - only there, because " is a legal character inside the SSID. In the regular expression above
^ means from start
$ means at end
\" means " (escaped)
.* means any number of characters
(...) means a capturing group, that can be referred by $1
So the whole expression means: replace "<something>" by <something> where $1 = <something>.
If there is no " at end/start, the regular expression doesn't match and nothing is replaced.
See Java Pattern class for more details.
For the mean time this is how I am getting around it, although its not great it will fix the issue.
public String removeQuotationsInCurrentSSIDForJellyBean(String ssid){
int deviceVersion= Build.VERSION.SDK_INT;
if (deviceVersion >= 17){
if (ssid.startsWith("\"") && ssid.endsWith("\"")){
ssid = ssid.substring(1, ssid.length()-1);
}
}
return ssid;
}
Two very simple variants:
string = string.replaceAll("^\" | \"$", "");
and
string = string.substring(1, string.length() - 1);
Faced the same problem! Used this technique which is backwards compatible:
if (suppliedSSID.equals(connectionInfo.getSSID()) || ("\"" + suppliedSSID + "\"").equals(connectionInfo.getSSID()) { DO SOMETHING }

Categories

Resources