Application scenario: SMS Sending for Android
Exception name:caused by:android.content.ActivityNotFoundException:No Activity found to handle Intent {act= Android.intent.action.SEND}
The source code is as follows:
PackageCom.phone.app.phone;
ImportAndroid.content.Intent;
ImportAndroid.net.Uri;
ImportAndroid.os.Bundle;
Importandroid.support.v7.app.AppCompatActivity;
ImportAndroid.telephony.SmsManager;
ImportAndroid.view.View;
ImportAndroid.widget.EditText;
ImportJava.util.ArrayList;
PublicclassSmsactivityextendsAppcompatactivityImplementsview.onclicklistener{
PrivateEditText edit =NULL;
PrivateEditText Smsedit =NULL;
@Override
protectedvoidOnCreate (Bundle savedinstancestate) {
Super. OnCreate (Savedinstancestate);
Setcontentview (r.layout.activity_sms);
Edit = (EditText) Findviewbyid (R.id.edit);//gets the object of the text
Smsedit = (EditText) Findviewbyid (r.id.sms);//gets the object of the text
//button btn = (button) Findviewbyid (R.ID.BTN);//gets the object of the button
//
// //Add a button event listener
//Btn.setonclicklistener (this);
}
PublicvoidOnClick (view view) {//Define how event correspondence is handled
String num = Edit.gettext (). toString ();//get the phone number in the text box
String Smstext = Smsedit.gettext (). toString ();
Intent Intent =NewIntent ();//Create an Intent
Smsmanager sm = Smsmanager.getdefault ();
Intent.setaction (Intent. Action_send);//set the action of intent
intent.setclassname ("Com.phone.app.phone", "com.phone.app.phone.SmsActivity");//set up activity to handle intent
arraylist<string> list = Sm.dividemessage (Smstext);//because a text message has a word limit, you need to split the long text message
for(String text:list) {
Sm.sendtextmessage (NUM,NULL, text,NULL,NULL);
}
//Intent.setdata (Uri.parse ("Tel:" +num));//set the data for intent
This. StartActivity (Intent);//use intent to open an interface
}
}
Solution:
Set the activity to handle intent,
intent.setclassname ("Com.phone.app.phone", "com.phone.app.phone.SmsActivity"); // set up activity to handle intent
You can resolve this bug!
The activitynotfoundexception of Bug-android