javascriptandroidtitaniumtitanium-sdk

Titanium App Not Requesting Call Phone Permission On Android


My Titanium app is not requesting permission to make a phone call. I have the following XML in my manifest tag of tiapp.xml:

<uses-feature android:name="android.permission.CALL_PHONE" android:required="false"/>

This is my JavaScript code:

var permissionsToRequest = [];
var callPhonePermission = "android.permission.CALL_PHONE";
var hasCallPhonePermission = Titanium.Android.hasPermission(callPhonePermission);

if (!hasCallPhonePermission) {
    permissionsToRequest.push(callPhonePermission);
}

if (permissionsToRequest.length > 0) {
    Titanium.Android.requestPermissions(permissionsToRequest, function(e) {
        if (e.success) {
            Ti.API.info("SUCCESS");
        } else {
            Ti.API.info("ERROR: " + e.error);
        }
    });
}

This is what I am seeing in the logcat when I hook up my phone to a computer running Android Studio:

ERROR: Permission(s) denied: android.permission.CALL_PHONE

Any ideas about what I may be doing wrong?


Solution

  • You have to use <uses-permission android:name="android.permission.CALL_PHONE" /> in your tiapp.xml. It is a permission not a feature.

    A full example that works for me:

    const win = Ti.UI.createWindow();
    win.addEventListener("open", function() {
        Titanium.Android.requestPermissions(["android.permission.CALL_PHONE"], function(e) {
            if (e.success) {
                Ti.API.info("SUCCESS");
            } else {
                Ti.API.info("ERROR: " + e.error);
            }
        });
    })
    win.open();
    

    There is no need to check the permission first before requesting it. If you have it already it will go to the success branch right away.