问题
I'm very much a beginner at this and I'm struggling to get this to work.
When button is pressed, I simply want the dialer to open with the specified number automatically inputted.
So far I've tried the following:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:00000000"));
startActivity(callIntent);
}
});
I've also tried:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneno="00000000";
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse(phoneno));
startActivity(i);
}
});
I've added the permission ACTION_CALL to the manifest.
Whenever I click the Call button the app force closes.
Any assistance would be greatly appreciated.
Thank you!
回答1:
String number = "12345678";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
You need to add this Permission to your manifest.
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
回答2:
i think you Must add <uses-permission android:name="android.permission.CALL_PHONE" />
in Manifest.
回答3:
If you want the dialer to open with the number use ACTION_DIAL
Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + phoneno));
You do not need any permission
回答4:
Make sure you have added the
<uses-permission android:name="android.permission.CALL_PHONE" />
tag at a correct level in the AndroidManifest.xml file (outside the
<application ... />
tag but within the <manifest ... />
tag):
回答5:
Try this.
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno)));
Also, add the permission android.permission.CALL_PHONE
in your manifest
file.
回答6:
Add the following in the manifest file and it should work fine -
<uses-permission android:name="android.permission.CALL_PHONE"/>
回答7:
In your Android Phone Go to: "Setting"-> "InstalledApp"-> "find your app"-> "App Permission"-> "Here allow the "Telephone Permission" Hope it will help you
来源:https://stackoverflow.com/questions/16412480/how-can-i-call-a-number-from-button-press-in-android