How To Detect If Device Is Capable Of Calling And Messaging
Some devices ie. Galaxy Tablet 10.1 can only send SMS, but cannot call. Some other devices like Asus Transformer don't even have SIM card. How can I detect if device can makes call
Solution 1:
Using this technic you can test all sorts of things too e.g. compass, is location available
PackageManagerpm= getBaseContext().getPackageManager();
pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
Solution 2:
Maybe you can query the PackageManager whether the system contains any component that can respond to ACTION_CALL and ACTION_SENDTO intents? You might need to add the "tel:" and "smsto:" scheme in the URI.
Solution 3:
That should do it:
PackageManager pm = this.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
System.out.println("horray");
} else {
System.out.println("nope");
}
Solution 4:
You can use the below method to check if sms feature is supported or not:
privatevoidsendSms(String theNumber, String theMsg) {
// TODO Auto-generated method stubStringSENT = "Message Sent";
StringDELIVERED = "Message Delivered";
PendingIntent sentPI = PendingIntent.getBroadcast(getApplicationContext(), 0, newIntent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getApplicationContext(), 0, newIntent(DELIVERED), 0);
registerReceiver(newBroadcastReceiver() {
@OverridepublicvoidonReceive(Context context, Intent intent) {
// TODO Auto-generated method stubswitch(getResultCode()){
caseActivity.RESULT_OK: Toast.makeText(getApplicationContext(), "Message Sent", Toast.LENGTH_SHORT).show();
break;
caseActivity.RESULT_CANCELED: Toast.makeText(getApplicationContext(), "Message Not Sent", Toast.LENGTH_SHORT).show();
break;
caseSmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getApplicationContext(), "No Service Available", Toast.LENGTH_SHORT).show();
break;
}
}
}, newIntentFilter(SENT));
registerReceiver(newBroadcastReceiver() {
@OverridepublicvoidonReceive(Context context, Intent intent) {
// TODO Auto-generated method stubswitch(getResultCode()){
caseActivity.RESULT_OK: Toast.makeText(getApplicationContext(), "Message Delivered", Toast.LENGTH_SHORT).show();
break;
caseActivity.RESULT_CANCELED: Toast.makeText(getApplicationContext(), "Message Not Delivered", Toast.LENGTH_SHORT).show();
break;
}
}
}, newIntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(theNumber, null, theMsg, sentPI, deliveredPI);
}
Solution 5:
You can just wrap your code in try/catch. It works in all cases, even with the last api changes about sms sending.
try{
// code that use telephony features
}
catch(Exception e){
// code that doesn't use telephony features
}
Post a Comment for "How To Detect If Device Is Capable Of Calling And Messaging"