0
我用三個按鈕做了一個應用程序。一個打電話,一個發送電子郵件,第三個發送短信。在第一次發佈後,我注意到電子郵件按鈕沒有響應。我試圖找到一個eroor但不能。所以我切換代碼,以便電子郵件按鈕發送短信和短信按鈕發送電子郵件。再一次,現在應該發送短信的電子郵件按鈕,沒有迴應。有任何想法嗎?Android按鈕錯誤
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 = "[email protected]";
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;
}
}
}}
哎呀。抱歉。我忘了在main.xml中添加android:onClick – QuantumFoam