The activitynotfoundexception of Bug-android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.