Ejemplo n.º 1
0
        public async override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            ComponentName me = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);

            widgetView = new RemoteViews(context.PackageName, Resource.Layout.widget);
            string     Apikey = "0123456789abcdef0123456789abcdef";
            string     url    = "https://api.kiezelpay.com/api/merchant/today?offset={0}&key=";
            int        utc    = Math.Abs((DateTimeKind.Local - DateTimeKind.Utc) * 60);
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");

            //HttpClient client = new HttpClient();
            HttpResponseMessage laresponse = new HttpResponseMessage();

            //laresponse.Version = new Version("1.1");
            //laresponse.RequestMessage.Version = new Version("1.1");
            laresponse = await client.GetAsync(String.Format(url, utc.ToString()) + Apikey);


            if (laresponse.IsSuccessStatusCode)
            {
                var toto = await laresponse.Content.ReadAsStringAsync();

                Console.WriteLine(toto);
                toto = "{\"datakiezel\":" + toto.ToString() + "}";



                mydata resultat = JsonConvert.DeserializeObject <mydata>(toto);


                widgetView.SetTextViewText(Resource.Id.amount, resultat.datakiezel.amount.ToString() + "$");

                widgetView.SetTextViewText(Resource.Id.valpurchase, resultat.datakiezel.purchases.ToString());

                widgetView.SetTextViewText(Resource.Id.rank, resultat.datakiezel.rank.ToString());

                widgetView.SetTextViewText(Resource.Id.date, String.Format("{0:HH:mm}", DateTime.Now));

                appWidgetManager.UpdateAppWidget(me, BuildRemoteViews(context, appWidgetIds));
            }
        }
Ejemplo n.º 2
0
        async void maj(string platform)
        {
            int    utc  = Math.Abs((DateTimeKind.Local - DateTimeKind.Utc) * 60);
            string _url = String.Format(url, utc.ToString()) + Apikey;

            if (platform != "")
            {
                _url += "&platform=fitbit";
            }

            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");

            //HttpClient client = new HttpClient();
            HttpResponseMessage laresponse = new HttpResponseMessage();

            //laresponse.Version = new Version("1.1");
            //laresponse.RequestMessage.Version = new Version("1.1");
            laresponse = await client.GetAsync(_url);


            if (laresponse.IsSuccessStatusCode)
            {
                var toto = await laresponse.Content.ReadAsStringAsync();

                Console.WriteLine(toto);
                toto = "{\"datakiezel\":" + toto.ToString() + "}";



                mydata   resultat = JsonConvert.DeserializeObject <mydata>(toto);
                TextView gain     = FindViewById <TextView>(Resource.Id.amount);
                gain.Text = resultat.datakiezel.amount.ToString() + "$";
                TextView nbachat = FindViewById <TextView>(Resource.Id.valpurchase);
                nbachat.Text = resultat.datakiezel.purchases.ToString();
                TextView rang = FindViewById <TextView>(Resource.Id.rank);
                rang.Text = resultat.datakiezel.rank.ToString();
            }
        }