0

我用三个按钮制作了一个应用程序。一个打电话,一个发邮件,第三个发短信。第一次成功后,我注意到电子邮件按钮没有响应。我试图找到一个eroor,但不能。所以我切换了代码,以便电子邮件按钮发送短信,短信按钮发送电子邮件。现在应该发送短信的电子邮件按钮再次没有响应。有任何想法吗?

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
 import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ContactDaveActivity extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


}

public void buttonhandler(View view)
{
    switch(view.getId())
    {
    case R.id.button1:
    {
        try {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:xxxxxxxxxx"));
            startActivity(callIntent);
        }
        catch(ActivityNotFoundException activtyException)
        {
            Throwable e = null;
            Log.e("dialingexample", "Call failed", e);
        }
        break;
    }
    case R.id.button2:
    {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain"); 
        String s = "xyz@gmail.com";
        i.putExtra(Intent.EXTRA_EMAIL, new String[]{s });
        startActivity(Intent.createChooser(i, "Send mail..."));
        break;

    }
    case R.id.button3:
    {
        String phoneNumber = "+xxxxxxxx";
        Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
        smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
        smsIntent.setType("vnd.android -dir/mms-sms");
        smsIntent.setData(Uri.parse("sms:"+phoneNumber));
        startActivity(smsIntent);
        break;
    }

}

} }

4

1 回答 1

1

你有android:onClick="buttonhandler"你的 main.xml 文件吗?

并检查 all,button1,button2,button3

<Button android:id="@id/button1" android:onClick="buttonhandler" ... />

<Button android:id="@id/button2" android:onClick="buttonhandler" ... />

<Button android:id="@id/button3" android:onClick="buttonhandler" ... />
于 2012-05-17T11:30:35.567 回答