I had somehow implemented the process of making a call with the Android app, so I would like to describe it here again and take revenge on my own.
By using ACTION_CALL of Intent, you can make a call with the number entered on the application side.
By using Intent's ACTION_DIAL, you can open the dialer and phone app with the number entered on the app side.
The concept of permissions has changed since Android 6.0, and it has been divided into two types: permissions that require permissions for users and permissions that do not.
※review -Nomal permission: When installing the app, permission can be obtained based on the description in AndroidManifest.xml. -Dangerous permission: Permission can be obtained with the permission of the user. The authority can be revoked later by the user.
There are also Dangerous permissions related to the phone (permissions that belong to the permission group PHONE), so let's set to get the necessary permissions according to the purpose.
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:012345678"));
startActivity(intent);
AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
You may not be able to connect because you do not have permission to connect to the dialog / phone application. With this basic code, in the case of an exception, the phone will not be connected and there will be no notification on the screen, and the user will not know what is going on.
Therefore, let's add exception handling and set to notify the user of the exception content at the time of exception.
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:012345678"));
//Exception handling from here
try{
startActivity(intent);
}catch(e: SecurityException){
Toast.makeText(context, "It's an error ...", Toast.LENGTH_SHORT).show()
}
・ Get each authority in advance. ・ Let's make a call using Intent. -Implement exception handling in case of an error. -Let's build measures for users who try to make outgoing operations on the app even though they do not have permission.
Recommended Posts