【发布时间】:2021-07-15 23:52:19
【问题描述】:
我想使用一键拨打电话。电话号码应该在里面。但是我的代码不起作用。谁能支持?
公共类 MainActivity 扩展 AppCompatActivity { 私有Button按钮;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
}
public void onClickStart(View view) {
button = findViewById(R.id.button);
((Button)findViewById(R.id.button)).setOnClickListener((View.OnClickListener) v -> {
Intent callIntent = new Intent(Intent.ACTION_CALL);
String phNum = "tel:" + "89261234567";
callIntent.setData(Uri.parse(phNum));
startActivity( callIntent) ;
});
}
}
清单文件
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GateApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
【问题讨论】:
标签: java android phone-call