i want to make call on an emergency number by pressing the button in my mobile app with help of ACTION_CALL but i didn't. why?
I implemented CALL_PHONE permission in my manifest file.
<uses-permission android:name="android.permission.CALL_PHONE"/>
and this is my java code to call.
public void makeCall(View v){
if (ActivityCompat.checkSelfPermission(this,Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED){
Toast.makeText(getApplicationContext(), "making call", Toast.LENGTH_LONG).show();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
callIntent.setData(Uri.parse("tel:108"));
startActivity(callIntent);
}else{
Toast.makeText(getApplicationContext(), "making call is not possible", Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CALL_PHONE},MY_PERMISSIONS_REQUEST_CALL_PHONE);
}
}
this code takes me onto default dialer of mobile.
How can i call on an emergency number directly by my app without reaching on default dialer?
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+123));//change the number
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE},12);
}else{
startActivity(callIntent);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.