In my app, I am creating one Activity
with several TextView
that collects information from a database SQLite
integrated in my app, and one of the data is the phone.
My intention with this data was to be able to create a button in it Activity
, which when pressed, would make the call to the phone number of the DB record that is shown on the screen, but I have come across that for each version of Android it is done differently. a way, for example:
For Android 5.0:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
But for Android 6.0 I have no idea how to do it and of course, it not only has to be for the latest version, but it has to be compatible with the others.
My question is:
How do I create a permission to make calls compatible with Android 6.0 and earlier?
I hope you can give me a hand and an example. :)
Thanks to everyone beforehand.
I leave you the example of the link developer.android.com/training/permissions/requesting.htm which I just did, taking advantage of the fact that I will also have to implement it.
Request permissions only from 6.0:
Receive user response:
I tried it and it works fine anyway now I will also try @Elenasys example. All the best.
For applications with Android OS prior to 6.0 it is enough to define the permission inside your file
AndroidManifest.xml
:Require permissions on Android 6.0 or later.
This would be the way to require permissions to be able to make phone calls in
Android 6.0
: