SDK Android vs SDK iPhone
Pour vous donner une idée rapide sur les deux SDK (iPhone & Android), voici quelques exemples de code repris de mon précédent article :
Connaitre le statut du GPS :
Android
public boolean isGpsEnabled(LocationManager lm){
List<String> locationProvidersEnabled = lm.getProviders(true);
for (Iterator<String> iterator = locationProvidersEnabled.iterator(); iterator.hasNext();) {
String provideName = iterator.next();
if (LocationManager.GPS_PROVIDER.equals(provideName)) return true;
}
return false;
}
iPhone
CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
if(locationManager.locationServicesEnabled)...
Envoyer un SMS :
Android
String message = "Mon message";
String phoneNumber = "+3361234569";
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, MyActivity.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message.toString(), pi, null);
iPhone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://3361234569"]];
Sur iPhone, il n'est pas possible d'envoyer un SMS de manière automatique, ce code ouvre seulement l'éditeur.
Composer un numéro :
String phoneNumber = "+3361234569";
Intent itent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneNumber));
startActivity(itent);
iPhone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+3361234569"]];
Lire MP3 :
Android
Fichier bip.mp3 stocké dans le répertoire "/res/raw" de l'application Android
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.bip);
mp.start();
iPhone
NSString *path = [[NSBundle mainBundle] pathForResource:@"ZZZZ" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
Merci à Rabii pour les exemples iPhone.