Karim Saleh
Karim Saleh

Reputation: 38

Azure with Xamarin.Android "You must be logged in to use this application"

I am recently starting to learn mobile development for my Final Year Project, and I am doing an Android application using Xamarin.Android and Azure Mobile Services. I have created a Test DB and created one entry there, trying to make my Android App to connect to the DB and retrieve this entry. I am doing this to get an idea how to establish a connection and retrieve data, and from there I will start modification properly. That is how my Model class look like (note that JSON properties are named exactly like the columns names in my DB.

using Newtonsoft.Json;

namespace com.parkkl.intro.Models
{
    class TestTable
    {
        public int Id { get; set; }

        [JsonProperty(PropertyName = "UserName")]
        public string UserName { get; set; }
        [JsonProperty(PropertyName = "deleted")]
        public bool Deleted { get; set; }
        [JsonProperty(PropertyName = "version")]
        public string Version { get; set; }
        [JsonProperty(PropertyName = "createdAt")]
        public string Creation { get; set; }
        [JsonProperty(PropertyName = "updatedAt")]
        public string Updated { get; set; }
    }
}

And that is how my activity look like

using Android.App;
using Microsoft.WindowsAzure.MobileServices;
using Android.OS;
using com.parkkl.intro.Models;
using System.Collections.Generic;
using Android.Widget;

namespace com.parkkl.intro
{
    [Activity(Label = "ParkKL", MainLauncher = false, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        #region Variables
        public static MobileServiceClient client = new MobileServiceClient
            (@"http://parkkl.azurewebsites.net/");
        private IMobileServiceTable<TestTable> test = null;
        private List<TestTable> testItems;
        #endregion

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            test = client.GetTable<TestTable>();

            testItems = new List<TestTable>();

            GetData();

        }

        public async void GetData()
        {
            var collection = await test.Where(user => user.Id == 1).ToCollectionAsync();

            foreach (var item in collection)
            {
                testItems.Add(
                    new TestTable
                    {
                        Id = item.Id,
                        UserName = item.UserName,
                        Deleted = item.Deleted,
                        Version = item.Version,
                        Creation = item.Creation,
                        Updated = item.Updated,
                    });
            }
            var finalItem = collection[0];
            TextView text = (TextView)FindViewById(Resource.Id.TextFromDB);
            text.Append(finalItem.UserName);
        }
    }
}

Now the issue is, every time I try to deploy the app, it throws this exception

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: You must be logged in to use this application

In my App Service in Azure, I have disabled all authentications, still I get this error. I am wondering where the issue is coming from?! I will much appreciate your help.

EDIT: I guess I found the issue, which was the permissions given on the table itself. However, I am still finding out a way to authenticate my app properly

Upvotes: 1

Views: 187

Answers (1)

Adrian Hall
Adrian Hall

Reputation: 8035

Check out the book http://aka.ms/zumobook for details on how to deal with authentication.

Upvotes: 0

Related Questions