求大神帮解答 为什么打电话时总是强制退出
yuan! 2018-12-19 01:22:38 public class MainActivity extends Activity {
private EditText etName;
private EditText etPhone;
private EditText etAddress;
private EditText etContent;
private Button btcall, btmsg;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etName = (EditText) findViewById(R.id.etName);
etPhone = (EditText) findViewById(R.id.etPhone);
etAddress = (EditText) findViewById(R.id.etAddress);
etContent = (EditText) findViewById(R.id.etContent);
btcall = (Button) findViewById(R.id.btcall);
btmsg = (Button) findViewById(R.id.btmesg);
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void click(View v){
int id = v.getId();
String name = etName.getText().toString();
String Phone = etPhone.getText().toString();
String address = etAddress.getText().toString();
String cont = "name=" + name + ",Phone=" + Phone + ",address=" + address ;
if(id== R.id.btnSave){
try {
FileOutputStream fos = this.openFileOutput("dbet.txt", Context.MODE_WORLD_WRITEABLE);
fos.write(cont.getBytes());
fos.close();
Toast.makeText(this, "写入完成", Toast.LENGTH_SHORT).show();
etName.getText().clear();
etPhone.getText().clear();
etAddress.getText().clear();
} catch (Exception e) {
e.printStackTrace();
}
}
//read
else if(id == R.id.btnRead){
try {
FileInputStream fis = this.openFileInput("dbet.txt");
byte[] bytes = new byte[fis.available()];
fis.read(bytes);
fis.close();
etContent.setText(new String(bytes));
} catch (Exception e) {
e.printStackTrace();
}
}
btcall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + etPhone.getText());
intent.setData(data);
startActivity(intent);
}
});
btmsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri sms = Uri.parse("smsto:" + etPhone.getText());
Intent intent = new Intent(Intent.ACTION_SENDTO, sms);
MainActivity.this.startActivity(intent);
}
});
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="姓名:"
/>
<EditText
android:id="@+id/etName"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="电话:"
/>
<EditText
android:id="@+id/etPhone"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="地址:"
/>
<EditText
android:id="@+id/etAddress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btcall"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="打电话"
android:onClick="click"
/>
<Button
android:id="@+id/btmesg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="发短信"
android:onClick="click"
/>
<Button
android:id="@+id/btnSave"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="保存"
android:onClick="click"
/>
<Button
android:id="@+id/btnRead"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="读取"
android:onClick="click"
/>
<Button
android:id="@+id/btnSDSave"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="SDSave"
android:onClick="click"
/>
<Button
android:id="@+id/btnOpenXml"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Xml解析"
android:onClick="click"
/>
</LinearLayout>
<EditText
android:id="@+id/etContent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="left|top"
/>
</LinearLayout>