适用于6.0之前的操作系统的Titanium Android Geolocation权限

时间:2016-06-24 21:25:58

标签: titanium appcelerator appcelerator-titanium

所以我已经成功获得了Android 6.0及更高版本的Geolocation权限,但我无法让它适用于Android 4.4.4。

我一直在控制台中收到这些错误

 dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
[DEBUG] :  dalvikvm: VFY: replacing opcode 0x6e at 0x0002
[INFO] :   dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType

这是来自这个

var hasLocationPermissions = Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);

现在我在TiApp.xml中添加了以下权限

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <application android:theme="@style/Theme.NoActionBar"/>
        <!-- Camera Permissions -->
        <uses-permission android:name="android.permission.CAMERA"/>
        <uses-feature android:name="android.hardware.camera"/>
        <uses-feature android:name="android.hardware.camera.autofocus"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
    </manifest>
</android>

仍然没有运气。这是我用来执行此操作的代码。我甚至试图通过检查版本

来规避
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;
    Titanium.Geolocation.purpose = 'Get Current Location to search local Items';
    var hasLocationPermissions = Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);

    if (Titanium.Platform.model != "Simulator"){
        Ti.API.info("ANDROID VERSION:"+Ti.Platform.version);
        if(Alloy.Globals.versionCompare(Ti.Platform.version, "6.0") == -1){
            getCurrentPosition();
        } else
        {
            if(hasLocationPermissions == true){
                 getCurrentPosition();
            } else {
                var win = Alloy.createController('locationPermission', {callback: function(e){
                    Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
                        if (e.success) {
                            getCurrentPosition();
                        } else {
                            Alloy.Globals.createAlertDialog('There seem to be issues with determining your location.\Please enable Location Services in your Settings to use Fluid');
                        }
                    });
                }}).getView();
                win.open(); 
            }
        }

    } else {
        Ti.API.info("LOCATION FOR SIMULATOR SET TO GALVANIZE - 1644 PLATTE DENVER");
        Alloy.Globals.currentLocation =  {attributes:{coordinates:{"lat": 39.757885, "lng": -105.0082375}}};//Galvanize
        if(successCallback) successCallback();
    }   

有人解决了这个问题吗?我在5.2.0 GA

1 个答案:

答案 0 :(得分:1)

根据我的经验,6版之前的Android版本或23以下的SDK版本继续在安装时要求所有权限。因此,只有Android 6及更高版本或SDK 23及更高版本才需要使用该功能时的新权限请求。我说5.3GA应用程序在请求位置时要求获得marshmallow的权限,但是版本<6的手机会像往常一样在安装时询问权限。我的代码没有任何基于android版本的条件逻辑。