求大神帮解答 为什么打电话时总是强制退出

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>
...全文
85 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 10 楼 无fucker说的回复:
[quote=引用 8 楼 无fucker说 的回复:]
手机系统是6.0及以上的话就要动态申请权限
log日志贴不出来.........无FUCK说


还有不知道什么事动态申请权限,找度娘[/quote] 好啵 不过谢谢啦
雕·不懒惰 2018-12-19
  • 打赏
  • 举报
回复
引用 8 楼 无fucker说 的回复:
手机系统是6.0及以上的话就要动态申请权限
log日志贴不出来.........无FUCK说


还有不知道什么事动态申请权限,找度娘
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 8 楼 无fucker说的回复:
手机系统是6.0及以上的话就要动态申请权限
log日志贴不出来.........无FUCK说
我是在虚拟机中运行 会显示强制退出
雕·不懒惰 2018-12-19
  • 打赏
  • 举报
回复
手机系统是6.0及以上的话就要动态申请权限
log日志贴不出来.........无FUCK说
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 4 楼 王能的回复:
很明显你没有动态申请权限,打电话权限是需要动态申请的。 建议跳到电话页面就行了,可以自行百度Android跳到打电话。 如果必须立即打电话,百度android动态申请权限
是 Androidmanifest里加call phone权限么
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 5 楼 无fucker说的回复:
[quote=引用 3 楼 qq_40285039 的回复:]
[quote=引用 1 楼 无fucker说的回复:]
权限加了没,Log贴出来

你说的log是logcat显示的东西么[/quote]

强制退出没有崩溃日志的么?[/quote] 有那个东西 出了很多东西 但是粘贴出不来
雕·不懒惰 2018-12-19
  • 打赏
  • 举报
回复
引用 3 楼 qq_40285039 的回复:
[quote=引用 1 楼 无fucker说的回复:]
权限加了没,Log贴出来

你说的log是logcat显示的东西么[/quote]

强制退出没有崩溃日志的么?
王能 2018-12-19
  • 打赏
  • 举报
回复
很明显你没有动态申请权限,打电话权限是需要动态申请的。 建议跳到电话页面就行了,可以自行百度Android跳到打电话。 如果必须立即打电话,百度android动态申请权限
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 1 楼 无fucker说的回复:
权限加了没,Log贴出来
你说的log是logcat显示的东西么
yuan! 2018-12-19
  • 打赏
  • 举报
回复
引用 1 楼 无fucker说的回复:
权限加了没,Log贴出来
权限加了 log 特别多
雕·不懒惰 2018-12-19
  • 打赏
  • 举报
回复

权限加了没,Log贴出来

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧