Java - How to Retrieve and use a single value from azure mobile services in Android

前端 未结 3 426
情深已故
情深已故 2021-01-21 02:25

I am new to azure but i know certain things like how to retrieve and store data to azure , i followed azure official documentation for this purpose.

Link is Here - https

3条回答
  •  时光说笑
    2021-01-21 02:48

    You can do this with a custom API. See this link: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/#custom-api

    Code looks like this:

    exports.post = function(request, response) {
        response.send(200, "{ message: 'Hello, world!' }");
    } 
    

    It's then reachable at https://todolist.azure-mobile.net/api/APIFILENAME.

    If you want to access a table you can do something like:

    exports.post = function(request, response) {
        var userTable = tables.getTable('users');
    
        permissionsTable
            .where({ userId: user.userId})
            .read({ success: sendUser });
    } 
    
    function sendUser(results){
      if(results.length <= 0) {
        res.send(200, {});
      } else {
        res.send(200, {result: results[0]});
      }
    }
    

    You can then follow the instructions for using the API on your Android client here: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-call-custom-api/

    How your app is written will change how this code works/looks, but it looks something like:

    ListenableFuture result = mClient.invokeApi( "UsersAPI", MarkAllResult.class ); 
    

    That invokes the API. You need to write the class and Future to handle the results. The above page explains this in great detail.

提交回复
热议问题