In my Android app, I use the following code to start the messaging app and populate the default text for the text message:
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("sms:"+USERS_PHONE_NUMBER)); intent.putExtra("sms_body", "DUMMY TEXT"); startActivity(intent);
This works in most cases. But unfortunately, on some devices the following error message appears:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=sms:+XXXXXXXXXX (has extras) } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1510) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) at android.app.Activity.startActivityForResult(Activity.java:3131) at android.app.Activity.startActivity(Activity.java:3237)
Obviously, the intention that I created cannot be processed.
- Is there any error in my SMS intent code?
- How can I prevent the application from crashing if the intention cannot be fulfilled?
Should I use PackageManager.queryIntentActivities () or is there any other way to solve this problem?
Thanks in advance!
source share