目前我正在Android中的消息撰寫屏幕上工作,使用Intent顯示消息撰寫屏幕,然後輸入電話號碼和消息。如何在Android中發送消息?
我已經設置了一個sendSMS
發送按鈕的方法,但是,當我按發送按鈕它沒有調用sendSMS
方法。
如何在消息撰寫屏幕中設置發送按鈕的方法?請幫幫我。 是否可以設置發送按鈕的方法?
由於提前
,供大家參考源代碼如下:
Texts.Java類
public class Texts extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.message_tab_screen);
Button Compose =(Button) findViewById(R.id.button1);
Compose.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.putExtra("sms_body", "");
Uri data = Uri.parse("sms:");
intent.setData(data);
startActivity(intent);
}
});
}
//---sends an SMS message method
private void sendSMS(String phoneNumber, String message)
{
System.out.println("SEND MESSAGE");
}
}
message_tab_screen.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Message Compose " />
</RelativeLayout>
其實你調用系統意圖 Intent intent = new Intent(「android.intent.action.VIEW」); 因此,您無法爲發送按鈕設置任何控件。你必須設計自定義頁面和按鈕來實現你的想法。 –
感謝您的回覆,是的,我用意圖創建消息撰寫屏幕,是否可以設置發送按鈕的方法? – SampathKumar