We know that implicit intents are used to perform an action that your application can't but others can do.
Like to send some sms we uses this intent :
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, textMessage);
intent.setType(HTTP.PLAIN_TEXT_TYPE);
startActivity(sendIntent);
But do you know this can crash your app if your device doesn't have target activity to send sms.
To solve this we use resolveActivity method like this :
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else{
//Activity not found
}
0 Comment(s)