Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4864] Callback not called in requestLocationPermissions on Android

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2017-03-27T18:39:16.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterDebuisson Eugène
AssigneeShak Hossain
Created2017-03-20T14:24:41.000+0000
Updated2018-03-06T07:47:55.000+0000

Description

Hello, When I use Ti.Geolocation.requestLocationPermissions the callback is not called at all on Android. I tried to put Ti.API.error or alert in it but nothing happened.
Ti.Geolocation.requestLocationPermissions(Titanium.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
            Ti.API.error('hello');
            Ti.API.error(JSON.stringify(e));
        });
}}
I'm using SDK 6.0.2 and building on Android.

Comments

  1. Sharif AbuDarda 2017-03-20

    Hello, AUTHORIZATION_ALWAYS is only for iOS and windows app. Not supported for Android. I can get the logs by the below code.
       var win = Ti.UI.createWindow({
           theme : "Theme.AppCompat.Fullscreen",
           backgroundColor : '#fff'
       });
       
       var btn = Ti.UI.createButton({
           title : 'Pick',
           top : 50,
       });
       btn.addEventListener('click', function() {
           Ti.Geolocation.requestLocationPermissions(Titanium.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
               Ti.API.error('hello');
               Ti.API.error(JSON.stringify(e));
           });
       });
       win.add(btn);
       
       win.open();
       
    Location permissinon popup opens and allowing that gives this response.
       [ERROR] :  hello
       [ERROR] :  {"code":0,"success":true}
       
    Once the permission is granted later try would not show the permission popup and the log for click on the button. You need to remove the permission from settings. There seems to be no issue here. Thanks.
  2. Debuisson Eugène 2017-03-21

    In the docs I saw requestLocationPermissions was for Android too but didn't check the authorization type. So I tried this: {noformat} Ti.Android.requestPermissions(["android.permission.ACCESS_FINE_LOCATION"], function(e) { alert('hey'); Ti.API.error(JSON.stringify(e)); }); {noformat} And put into the manifest in the tiapp.xml. but still the callback is never called. Any idea why this isn't working ?
  3. Sharif AbuDarda 2017-03-21

    Hello, Try this sample code as a workaround.
       var win = Ti.UI.createWindow();
       var locationPermission = "android.permission.ACCESS_FINE_LOCATION";
       var hasLocationPermission = Ti.Android.hasPermission(locationPermission);
       var permissionsToRequest = [];
       
       if (!hasLocationPermission) {
           permissionsToRequest.push(locationPermission);
       }
       if (permissionsToRequest.length > 0) {
           Ti.Android.requestPermissions(permissionsToRequest, function(e) {
               if (e.success) {
                   Ti.API.info("SUCCESS");
                   win.open();
               } else {
                   Ti.API.info("ERROR: " + e.error);
               }
           });
       }
       if (hasLocationPermission) {
           win.open();
       }
       
       
  4. Debuisson Eugène 2017-03-22

    Hello, I tried that workaround but the callback isn't called.
  5. Sharif AbuDarda 2017-03-22

    Hello, Send the full code you are testing. The code I sent is working perfectly. It shows the success log. Thanks.
  6. Debuisson Eugène 2017-03-23

    I tried it in a new project.
  7. Sharif AbuDarda 2017-03-23

    Hello, Are you using my code? use the below code
       var win = Ti.UI.createWindow({
           theme : "Theme.AppCompat.Fullscreen",
           backgroundColor : '#fff'
       });
       
       var locationPermission = "android.permission.ACCESS_FINE_LOCATION";
       var hasLocationPermission = Ti.Android.hasPermission(locationPermission);
       
       Ti.Android.requestPermissions(["android.permission.ACCESS_FINE_LOCATION"], function(e) {
       
           if (e.success) {
               Ti.API.info("SUCCESS");
               win.open();
               alert("SUCCESS");
       
           } else {
               Ti.API.info("ERROR: " + e.error);
           }
       });
       if (hasLocationPermission) {
           win.open();
       }
       
    Callback only calls on first run on device. After you grant the access the callback calls and window opens. If you remove the permission from setting it should call again. Make sure you set
                   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
       
    in tiapp.xml. Thanks.
  8. Debuisson Eugène 2017-03-24

    Hello, This code works for me ! Thanks !
  9. Mitul Bhalia 2018-03-06

    The above code does not work for me with 6.0.2 and with 6.3.1 too. It does not call success or error callback. Can somebody help me to sort this out?

JSON Source