Skip to content Skip to sidebar Skip to footer

Making Your Android App Selectable To Handle Making A Call

I've had got allot of help from stackoverflow with programming problems over the years just off google. I have finally run into an issue that i cant solve despite exhaustive search

Solution 1:

You should look into the manifest of Skype or other apps that add this functionality. A quick look at Skype got me this;

<intent-filter        
    icon="@drawable/skype_blue"
    priority="0"><action name="android.intent.action.VIEW"/>
        <action name="android.intent.action.CALL"/>
        <action name="android.intent.action.DIAL"/>
        <action name="android.intent.action.CALL_PRIVILEGED"/>
        <category name="android.intent.category.DEFAULT"/>
        <data scheme="tel"/></intent-filter>

I just looked at TrueCaller (and it seems to work better in OS 6 (but not always) and here is the manifest details that might interest you.

<uses-permissionname="android.permission.MODIFY_PHONE_STATE"/><uses-permissionname="android.permission.CALL_PRIVILEGED"/><activitytheme="@android:style/Theme.NoDisplay"name="com.truecaller.ui.DialerIntentProxy"taskAffinity="com.truecaller.dialer"launchMode="singleInstance"noHistory="true"><intent-filter><actionname="com.truecaller.OPEN_DIALER" /><categoryname="android.intent.category.DEFAULT" /></intent-filter><intent-filter><actionname="android.intent.action.DIAL" /><categoryname="android.intent.category.DEFAULT" /></intent-filter><intent-filter><actionname="android.intent.action.DIAL" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.BROWSABLE" /><datascheme="voicemail" /></intent-filter><intent-filter><actionname="android.intent.action.DIAL" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.BROWSABLE" /><datamimeType="vnd.android.cursor.item/phone" /><datamimeType="vnd.android.cursor.item/person" /></intent-filter><intent-filter><actionname="android.intent.action.VIEW" /><actionname="android.intent.action.DIAL" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.BROWSABLE" /><datascheme="tel" /></intent-filter><intent-filter><actionname="android.intent.action.CALL_BUTTON" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.BROWSABLE" /></intent-filter><intent-filter><actionname="android.intent.action.VIEW" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.BROWSABLE" /><datamimeType="vnd.android.cursor.dir/calls" /></intent-filter><intent-filter><actionname="com.android.phone.action.RECENT_CALLS" /><categoryname="android.intent.category.DEFAULT" /><categoryname="android.intent.category.LAUNCHER" /></intent-filter><intent-filter><actionname="android.intent.action.VIEW" /><categoryname="android.intent.category.DEFAULT" /><datamimeType="vnd.android.cursor.item/calls" /></intent-filter><intent-filter><actionname="com.sec.android.app.dialertab.calllog.DetailViewActivity" /><categoryname="android.intent.category.DEFAULT" /></intent-filter><intent-filter><actionname="com.sec.android.app.dialertab.calllog.LogsListActivity" /><categoryname="android.intent.category.DEFAULT" /></intent-filter><intent-filter><actionname="android.intent.action.SEARCH_LONG_PRESS" /><categoryname="android.intent.category.DEFAULT" /></intent-filter></activity>

Remember, I am just using this for educational purposes. Re-using the code might have copyright issues.

Solution 2:

To achieve this on api 23 android marshmallow and future android versions pending tests.

Add this in the manifest inside the default launcher <activity> tags.

<intent-filter><actionandroid:name="android.intent.action.CALL"/><actionandroid:name="android.intent.action.CALL_PRIVILEGED"/><categoryandroid:name="android.intent.category.DEFAULT"/><dataandroid:scheme="tel"/></intent-filter>

Gain CALL_PRIVILEGED access by adding this into your code, such as when your activity first launches. This checks if the permission is granted and if it isn't it will ask the user for access.

if (Build.VERSION.SDK_INT >= 23) {
    if (ContextCompat.checkSelfPermission(this,
        Manifest.permission.CALL_PRIVILEGED)!=PackageManager.PERMISSION_GRANTED {
        if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
        Manifest.permission.CALL_PRIVILEGED)) {
        ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.CALL_PRIVILEGED},
            PERMISSIONS_REQUEST_CALL_PRIVILEGED);
        }
    }
}

Add this constant somewhere, such as the top of the activity file.

public static int PERMISSIONS_REQUEST_CALL_PRIVILEGED = 1;

This still seems to work on older android versions but not api 19 (Kitcat) onwards. I'm guessing this may be because i was unable to put a request for CALL_PRIVILEGED in the manifest, as android studio throws an error sayings its for system apps only and won't compile.

Post a Comment for "Making Your Android App Selectable To Handle Making A Call"