Appcelerator Konnte die Methode android.app.Activity.checkSelfPermission nicht finden

Ich kann nicht scheinen, Geo-Standort auf Android arbeiten zu bekommen scheinen nur den folgenden Fehler zu bekommen.

[INFO] :   dalvikvm: Could not find method android.app.Activity.checkSelfPermission, referenced from method ti.modules.titanium.geolocation.GeolocationModule.hasLocationPermissions
[WARN] :   dalvikvm: VFY: unable to resolve virtual method 32: Landroid/app/Activity;.checkSelfPermission (Ljava/lang/String;)I
[INFO] :   dalvikvm: Could not find method android.app.Activity.requestPermissions, referenced from method ti.modules.titanium.geolocation.GeolocationModule.requestLocationPermissions
[WARN] :   dalvikvm: VFY: unable to resolve virtual method 82: Landroid/app/Activity;.requestPermissions ([Ljava/lang/String;I)V

Mein Code lautet wie folgt.

Ti.Geolocation.purpose = "Please allow us to find you.";
//Ti.Geolocation.showCalibration = false;
if (OS_ANDROID) {
    Titanium.Geolocation.Android.LocationProvider = Ti.Geolocation.PROVIDER_GPS;
}
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 10;

Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
    console.log(e);

    if (!e.success || e.error) {

        var dialog = Ti.UI.createAlertDialog({
            message : 'You do not have location permissions enabled.',
            ok : 'Got it',
            title : 'Important'
        });

        dialog.addEventListener('click', function(e) {

            if (OS_IOS) {
                Ti.Platform.openURL('app-settings:');
            }

            if (OS_ANDROID) {
                var intent = Ti.Android.createIntent({
                    action : 'android.settings.APPLICATION_SETTINGS',
                });
                intent.addFlags(Ti.Android.FLAG_ACTIVITY_NEW_TASK);
                Ti.Android.currentActivity.startActivity(intent);
            }

        });

        dialog.show();

        return;

    }

    Titanium.Geolocation.getCurrentPosition(getGeoPosition);

});

Wenn ich das laufen lasse, ist es stundenlang veraltet, jetzt zu versuchen, so nahe daran zu sein, einfach alles aufzugeben, was mir einfällt.

Appcelerator 5.1.2.GA

OLLSTÄNDIGER CODE ZUM TEST

function getGeoPosition(_event) {
    console.log(_event);
    alert(JSON.stringify(_event));
}

Ti.Geolocation.purpose = "Please allow us to find you.";
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 10;

/**
 * Event listener added in the view.
 * Fired when user taps on the Ti.Geolocation button.
 */
function geolocation() {

    // The new cross-platform way to check permissions
    // The first argument is required on iOS and ignored on other platforms
    var hasLocationPermissions = Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS);

    if (hasLocationPermissions) {
        alert('You already have permission.');
        Titanium.Geolocation.getCurrentPosition(getGeoPosition);
    }

    // On iOS we can get information on the reason why we might not have permission
    if (OS_IOS) {

        // Map constants to names
        var map = {};
        map[Ti.Geolocation.AUTHORIZATION_ALWAYS] = 'AUTHORIZATION_ALWAYS';
        map[Ti.Geolocation.AUTHORIZATION_AUTHORIZED] = 'AUTHORIZATION_AUTHORIZED';
        map[Ti.Geolocation.AUTHORIZATION_DENIED] = 'AUTHORIZATION_DENIED';
        map[Ti.Geolocation.AUTHORIZATION_RESTRICTED] = 'AUTHORIZATION_RESTRICTED';
        map[Ti.Geolocation.AUTHORIZATION_UNKNOWN] = 'AUTHORIZATION_UNKNOWN';
        map[Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE] = 'AUTHORIZATION_WHEN_IN_USE';

        // Available since Ti 0.8 for iOS and Ti 4.1 for Windows
        // Always returns AUTHORIZATION_UNKNOWN on iOS<4.2
        var locationServicesAuthorization = Ti.Geolocation.locationServicesAuthorization;

        if (locationServicesAuthorization === Ti.Geolocation.AUTHORIZATION_RESTRICTED) {
            alert('Because permission are restricted by some policy which you as user cannot change, we don\'t request as that might also cause issues.');

        } else if (locationServicesAuthorization === Ti.Calendar.AUTHORIZATION_DENIED) {

            alert('You denied permission before');
        }
    }

    // The new cross-platform way to request permissions
    // The first argument is required on iOS and ignored on other platforms
    Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {

        if (e.success) {

            // Instead, probably call the same method you call if hasLocationPermissions() is true
            alert('You granted permission.');

        } else if (OS_ANDROID) {
            alert('You denied permission for now, forever or the dialog did not show at all because it you denied forever before.');

        } else {

            // We already check AUTHORIZATION_DENIED earlier so we can be sure it was denied now and not before
            Ti.UI.createAlertDialog({
                title : 'You denied permission.',

                // We also end up here if the NSLocationAlwaysUsageDescription is missing from tiapp.xml in which case e.error will say so
                message : e.error
            }).show();
        }
    });
}

geolocation();

// Handle the URL in case it resumed the app
Ti.App.addEventListener("resume", function() {
    geolocation();
});

Neueste Version finden ... 5.1.0 ✓ Version 5.1.0 ist bereits installiert. ? Planen Sie die Entwicklung von Titanium-Apps? J

Checking your environment...

You have the latest Titanium SDK release 5.1.2.GA
Congrats! No issues detected for developing cross-platform mobile apps!

appc setup complete!

UPDATE MANAGE, UM ES FUNKTIONIEREN ZU LASSEN ABER WARUM !!!!

Ok also habe ich es geschafft, es zum Laufen zu bringen, indem ich in die Einstellungen meiner Standorte gegangen bin und sie aus- und wieder eingeschaltet habe und auf Zustimmen geklickt habe ???? komisch kann nicht richtig sein?

Das ist soooo ärgerlich, dass ich das jedes Mal tun muss, damit die Standortdienste funktionieren?

Update Ich denke, einer der Hauptgründe, warum ich ein Problem bekommen habe, ist, dass ich Berechtigungen für jedes Laden des Post-Layout-Ereignis-Listeners angefordert habe. Dies scheint das Problem zu beheben.

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

 if (hasLocationPermissions) {
     alert('You already have permission.');
     Titanium.Geolocation.getCurrentPosition(getGeoPosition);
 } else {
     Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {

         if (e.success) {

             Titanium.Geolocation.getCurrentPosition(getGeoPosition);

         } else if (OS_ANDROID) {
             alert('You denied permission for now, forever or the dialog did not show at all because it you denied forever before.');

         } else {

             // We already check AUTHORIZATION_DENIED earlier so we can be sure it was denied now and not before
             Ti.UI.createAlertDialog({
                 title: 'You denied permission.',

                 // We also end up here if the NSLocationAlwaysUsageDescription is missing from tiapp.xml in which case e.error will say so
                 message: e.error
             }).show();
         }
     });

 }

Noch immer wieder treten andere Probleme auf, bei denen GPS nicht jedes Mal aktiviert wird. Behalten Sie dies bei und melden Sie sich mit Updates zurück.

Antworten auf die Frage(0)

Ihre Antwort auf die Frage