Android passing multiple numbers to SMS intent

2019-04-11 17:54发布

问题:

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?

回答1:

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'


回答2:

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...