android android.intent.action.call crashing Android app?
I am trying to make call from my app. But every time it get crashed with no error shown on logcat. I took permission in manifest also check it at runtime.
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
add a comment |
I am trying to make call from my app. But every time it get crashed with no error shown on logcat. I took permission in manifest also check it at runtime.
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
1
CALL_PHONEis runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .
– ADM
Nov 20 '18 at 11:48
add a comment |
I am trying to make call from my app. But every time it get crashed with no error shown on logcat. I took permission in manifest also check it at runtime.
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
I am trying to make call from my app. But every time it get crashed with no error shown on logcat. I took permission in manifest also check it at runtime.
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
asked Nov 20 '18 at 11:36
Abhishek Borikar
4919
4919
1
CALL_PHONEis runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .
– ADM
Nov 20 '18 at 11:48
add a comment |
1
CALL_PHONEis runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .
– ADM
Nov 20 '18 at 11:48
1
1
CALL_PHONE is runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .– ADM
Nov 20 '18 at 11:48
CALL_PHONE is runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .– ADM
Nov 20 '18 at 11:48
add a comment |
2 Answers
2
active
oldest
votes
Don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
An intent by itself is simply an object that describes something. It doesn't do anything.
public void call(String number){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
}
And How to make call in Android 6.0 and Above
add a comment |
Are you sure context is not null ? You should do something like this.
Inside your calling activity make these changes
private static final int REQUEST_CALL_PHONE_PERMISSION = 100;
if( isCallPhonePermissionGranted() ){
call("<Number>");
} else {
call("<Number>");
}
private void requestCallPermission() {
final String permissions = new String{Manifest.permission.CALL_PHONE};
ActivityCompat.requestPermissions(this, permissions, REQUEST_CALL_PHONE_PERMISSION);
}
private boolean isCallPhonePermissionGranted() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String
permissions, @NonNull int grantResults) {
if (requestCode != REQUEST_CALL_PHONE_PERMISSION) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
call("<Number>");
return;
}
}
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
And finally add this this permission to Android Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392162%2fandroid-android-intent-action-call-crashing-android-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
An intent by itself is simply an object that describes something. It doesn't do anything.
public void call(String number){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
}
And How to make call in Android 6.0 and Above
add a comment |
Don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
An intent by itself is simply an object that describes something. It doesn't do anything.
public void call(String number){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
}
And How to make call in Android 6.0 and Above
add a comment |
Don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
An intent by itself is simply an object that describes something. It doesn't do anything.
public void call(String number){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
}
And How to make call in Android 6.0 and Above
Don't forget to add the relevant permission to your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
An intent by itself is simply an object that describes something. It doesn't do anything.
public void call(String number){
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
}
And How to make call in Android 6.0 and Above
answered Nov 20 '18 at 12:06
Manish
257
257
add a comment |
add a comment |
Are you sure context is not null ? You should do something like this.
Inside your calling activity make these changes
private static final int REQUEST_CALL_PHONE_PERMISSION = 100;
if( isCallPhonePermissionGranted() ){
call("<Number>");
} else {
call("<Number>");
}
private void requestCallPermission() {
final String permissions = new String{Manifest.permission.CALL_PHONE};
ActivityCompat.requestPermissions(this, permissions, REQUEST_CALL_PHONE_PERMISSION);
}
private boolean isCallPhonePermissionGranted() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String
permissions, @NonNull int grantResults) {
if (requestCode != REQUEST_CALL_PHONE_PERMISSION) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
call("<Number>");
return;
}
}
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
And finally add this this permission to Android Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
add a comment |
Are you sure context is not null ? You should do something like this.
Inside your calling activity make these changes
private static final int REQUEST_CALL_PHONE_PERMISSION = 100;
if( isCallPhonePermissionGranted() ){
call("<Number>");
} else {
call("<Number>");
}
private void requestCallPermission() {
final String permissions = new String{Manifest.permission.CALL_PHONE};
ActivityCompat.requestPermissions(this, permissions, REQUEST_CALL_PHONE_PERMISSION);
}
private boolean isCallPhonePermissionGranted() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String
permissions, @NonNull int grantResults) {
if (requestCode != REQUEST_CALL_PHONE_PERMISSION) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
call("<Number>");
return;
}
}
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
And finally add this this permission to Android Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
add a comment |
Are you sure context is not null ? You should do something like this.
Inside your calling activity make these changes
private static final int REQUEST_CALL_PHONE_PERMISSION = 100;
if( isCallPhonePermissionGranted() ){
call("<Number>");
} else {
call("<Number>");
}
private void requestCallPermission() {
final String permissions = new String{Manifest.permission.CALL_PHONE};
ActivityCompat.requestPermissions(this, permissions, REQUEST_CALL_PHONE_PERMISSION);
}
private boolean isCallPhonePermissionGranted() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String
permissions, @NonNull int grantResults) {
if (requestCode != REQUEST_CALL_PHONE_PERMISSION) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
call("<Number>");
return;
}
}
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
And finally add this this permission to Android Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
Are you sure context is not null ? You should do something like this.
Inside your calling activity make these changes
private static final int REQUEST_CALL_PHONE_PERMISSION = 100;
if( isCallPhonePermissionGranted() ){
call("<Number>");
} else {
call("<Number>");
}
private void requestCallPermission() {
final String permissions = new String{Manifest.permission.CALL_PHONE};
ActivityCompat.requestPermissions(this, permissions, REQUEST_CALL_PHONE_PERMISSION);
}
private boolean isCallPhonePermissionGranted() {
return ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)
== PackageManager.PERMISSION_GRANTED;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String
permissions, @NonNull int grantResults) {
if (requestCode != REQUEST_CALL_PHONE_PERMISSION) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
return;
}
if (grantResults.length != 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
call("<Number>");
return;
}
}
public void call(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+number));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}
And finally add this this permission to Android Manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
answered Nov 20 '18 at 12:35
Ramesh Yankati
65848
65848
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392162%2fandroid-android-intent-action-call-crashing-android-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
CALL_PHONEis runtime permission have you asked it at runtime ? . Put a try catch and debug the Exception .– ADM
Nov 20 '18 at 11:48