Android应用停止拨打电话

时间:2018-02-06 09:59:27

标签: java android android-activity

这是主要活动。

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText number;
Button makecall;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    number = findViewById(R.id.number);
    makecall = findViewById(R.id.makecall);
    call();
}

private void call() {
    makecall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent;
            intent = new Intent(Intent.ACTION_DIAL);
            intent = intent.setData(Uri.parse("number:"+number.getText().toString()));
            startActivity(intent);
        }
    });
}
}

我将此权限请求添加到清单文件。

<uses-permission android:name="android.permission.CALL_PHONE"/>

这是我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.bimstajyer1.calisma10.MainActivity">

<EditText
    android:id="@+id/number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Number"
    android:inputType="number"
    android:maxLength="11" />

<Button
    android:id="@+id/makecall"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Make a call" />
</LinearLayout>

当我按下通话按钮拨打电话时,我收到此错误。

致命的例外:主要

  

处理:com.example.bimstajyer1.calisma10,PID:25198                                                                                  android.content.ActivityNotFoundException:找不到要处理的Activity   Intent {act = android.intent.action.DIAL dat = number:}

错误行是:startActivity(intent);

2 个答案:

答案 0 :(得分:1)

>>> '3,1,4'.split(',', min_elements=5)
['3', '1', '4', '', '']

>>> '3,1,4,159,dev'.split(',', min_elements=5)
['3', '1', '4', '159', 'dev']

}); }

现在跳过所有崩溃。

答案 1 :(得分:0)

请查看此

private void call() {
makecall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent;
        intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:"+number.getText().toString()));
        startActivity(intent);
    }
});
}