I am getting null value after deserialization of json. Below I posted c# code and json. I think I have done mistake in deserialization of json.Please any suggestion.
Getting Null Value After Deserialization of Json
How to detect fake location in Xamarin Forms
Hi Team,
I am developing one xamarin form app in which i am taking current lat long of user (GPS) using xamarin essentials. Here i want to stop user sending fake location using MOCK setting or Any Fake GPS APP.
Android:- To achieve this , i have created dependency service but always getting mock location as false using IsFromMockProvider.
I have tested it by Switch ON the Mock location APP named "FAKE GPS". My app still capturing fake location when user use it otherwise it gets real location.
Below is the code i have written
BELOW IS SHARED .NET CODE
1. Interface added
using System;
namespace SmartAttendance.Interfaces
{
public interface IMockLocation
{
Boolean IsMockLocation(Xamarin.Essentials.Location location);
}
}
//Calling Part
if(Device.RuntimePlatform == Device.Android)
{
mock = DependencyService.Get<IMockLocation>().IsMockLocation(position); //Here always getting mock as false even tried fake gps app //
}
BELOW IN ANDRIOD MAIN ACTIVITY
[assembly: Xamarin.Forms.Dependency(typeof(SmartAttendance.Droid.Mock))]
namespace SmartAttendance.Droid
{
public class Mock : IMockLocation
{
public Boolean IsMockLocation(Xamarin.Essentials.Location location) //Copying ESSENTIAL VARIABLE TO ANDRIOD LOCATION VARIABLE
{
Boolean isMock = false;
Context context = Android.App.Application.Context;
Location alocation = new Location("");
alocation.Latitude = location.Latitude;
alocation.Longitude =location.Longitude;
alocation.Accuracy = (float)location.Accuracy;
alocation.Altitude = (float) location.Altitude;
alocation.Speed = (float) location.Speed;
alocation.Time = location.Timestamp.Ticks;
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBeanMr2)
isMock = alocation.IsFromMockProvider; //using marshmallow so this part is executing
else
isMock = Settings.Secure.GetString( context.ContentResolver, Settings.Secure.AllowMockLocation).Equals("0"); //this is below jellybean
return isMock;
}
}
}
FOR IOS : NOT tried any thing yet. As i know its not much easy to set mock location in IOS as compare to ANDRIOD. But If any body can provide any thing it will be higly appreciable
So, Overall tried lot of things but couldn't succeed. Please help what wrong i am doing to stop sending Fake location.
xamarin forms Jsonreaderexception
I have a list showing stores on a page,upon clicking each store, corresponding categories and products are shown on a lists in another page. Stores,categories and products are displayed using Api calls.I am getting everything correct, but while navigating back and forth many times between store page and product page,Getting this error:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered
while parsing value: <. Path '', line 0, position 0.
Using breakpoint, not able to see the source of exception. How to handle this exception?
Edit: I am getting this html just before exception
[0:] <!doctype html>
<html lang="en">
<head>
<title>Too Many Requests</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
header,
nav,
section {
display: block;
}
figcaption,
main {
display: block;
}
a {
background-color: transparent;
-webkit-text-decoration-skip: objects;
}
strong {
font-weight: inherit;
}
strong {
font-weight: bolder;
}
code {
font-family: monospace, monospace;
font-size: 1em;
}
dfn {
font-style: italic;
}
svg:not(:root) {
overflow: hidden;
}
button,
input {
font-family: sans-serif;
font-size: 100%;
line-height: 1.15;
margin: 0;
}
button,
input {
overflow: visible;
}
button {
text-transform: none;
}
button,
html [type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
legend {
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: inherit;
display: table;
max-width: 100%;
padding: 0;
white-space: normal;
}
[type="checkbox"],
[type="radio"] {
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
}
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
[type="search"] {
-webkit-appearance: textfield;
outline-offset: -2px;
}
[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit;
}
menu {
display: block;
}
canvas {
display: inline-block;
}
template {
display: none;
}
[hidden] {
display: none;
}
html {
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-family: sans-serif;
}
*,
*::before,
*::after {
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
p {
margin: 0;
}
button {
background: transparent;
padding: 0;
}
button:focus {
outline: 1px dotted;
outline: 5px auto -webkit-focus-ring-color;
}
*,
*::before,
*::after {
border-width: 0;
border-style: solid;
border-color: #dae1e7;
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
border-radius: 0;
}
button,
input {
font-family: inherit;
}
input::-webkit-input-placeholder {
color: inherit;
opacity: .5;
}
input:-ms-input-placeholder {
color: inherit;
opacity: .5;
}
input::-ms-input-placeholder {
color: inherit;
opacity: .5;
}
input::placeholder {
color: inherit;
opacity: .5;
}
button,
[role=button] {
cursor: pointer;
}
.bg-transparent {
background-color: transparent;
}
.bg-white {
background-color: #fff;
}
.bg-teal-light {
background-color: #64d5ca;
}
.bg-blue-dark {
background-color: #2779bd;
}
.bg-indigo-light {
background-color: #7886d7;
}
.bg-purple-light {
background-color: #a779e9;
}
.bg-no-repeat {
background-repeat: no-repeat;
}
.bg-cover {
background-size: cover;
}
.border-grey-light {
border-color: #dae1e7;
}
.hover\:border-grey:hover {
border-color: #b8c2cc;
}
.rounded-lg {
border-radius: .5rem;
}
.border-2 {
border-width: 2px;
}
.hidden {
display: none;
}
.flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.items-center {
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.justify-center {
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.font-sans {
font-family: Nunito, sans-serif;
}
.font-light {
font-weight: 300;
}
.font-bold {
font-weight: 700;
}
.font-black {
font-weight: 900;
}
.h-1 {
height: .25rem;
}
.leading-normal {
line-height: 1.5;
}
.m-8 {
margin: 2rem;
}
.my-3 {
margin-top: .75rem;
margin-bottom: .75rem;
}
.mb-8 {
margin-bottom: 2rem;
}
.max-w-sm {
max-width: 30rem;
}
.min-h-screen {
min-height: 100vh;
}
.py-3 {
padding-top: .75rem;
padding-bottom: .75rem;
}
.px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
.pb-full {
padding-bottom: 100%;
}
.absolute {
position: absolute;
}
.relative {
position: relative;
}
.pin {
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.text-black {
color: #22292f;
}
.text-grey-darkest {
color: #3d4852;
}
.text-grey-darker {
color: #606f7b;
}
.text-2xl {
font-size: 1.5rem;
}
.text-5xl {
font-size: 3rem;
}
.uppercase {
text-transform: uppercase;
}
.antialiased {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.tracking-wide {
letter-spacing: .05em;
}
.w-16 {
width: 4rem;
}
.w-full {
width: 100%;
}
@media (min-width: 768px) {
.md\:bg-left {
background-position: left;
}
.md\:bg-right {
background-position: right;
}
.md\:flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.md\:my-6 {
margin-top: 1.5rem;
margin-bottom: 1.5rem;
}
.md\:min-h-screen {
min-height: 100vh;
}
.md\:pb-0 {
padding-bottom: 0;
}
.md\:text-3xl {
font-size: 1.875rem;
}
.md\:text-15xl {
font-size: 9rem;
}
.md\:w-1\/2 {
width: 50%;
}
}
@media (min-width: 992px) {
.lg\:bg-center {
background-position: center;
}
}
</style>
</head>
<body class="antialiased font-sans">
<div class="md:flex min-h-screen">
<div class="w-full md:w-1/2 bg-white flex items-center justify-center">
<div class="max-w-sm m-8">
<div class="text-black text-5xl md:text-15xl font-black">
429 </div>
<div class="w-16 h-1 bg-purple-light my-3 md:my-6"></div>
<p class="text-grey-darker text-2xl md:text-3xl font-light mb-8 leading-normal">
Sorry, you are making too many requests to our servers. </p>
<a href="http://beta.cybasetech.com/hotcool">
<button class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
Go Home
</button>
</a>
</div>
</div>
<div class="relative pb-full md:flex md:pb-0 md:min-h-screen w-full md:w-1/2">
<div style="background-image: url('/svg/403.svg');" class="absolute pin bg-cover bg-no-repeat md:bg-left lg:bg-center">
</div>
</div>
</div>
</body>
</html>
How to display listview in two columns
I have seen this question answered, but the responses don't apply to the situation I'm trying to address.
I want to display two separate list items in each row of a ListView. What I don't want is to line up vertically the fields in each record one to a row.
My aim is to list two complete records in each row, one in each column. Each cell would include the image and accompanying text, which are separate fields in the record.
This is a crude representation:
| R0 | R1 |
| R2 | R3 |
| R4 | R5 |
and so on . . .
I've tried using separate binding contexts for each column as well as putting each row in a tuple. But so far I can't figure out how to match the data to the binding of the ListView.
I'd be grateful to hear from anyone who's solved this problem.
Thanks
Foundation.MonoTouchException has been thrown in xamarin.forms
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch..
I am using Prism Structure with xamarin.forms.My app is runing on android properly.when i run my app on ios then exception is occur..
i cleaned the whole project and after build all project but still error is coming..if any one has any solution then please suggest me..
Can I use google cloud speech API in my xamarin.forms application?
Is it possible to integrate google cloud speech API in Xamarin.forms apps? If yes, Could you share steps or sample examples to achieve the same?
Thanks in advance!
Xamarin - Entity Framework - SqLite - GetItemsAsync : unable to open database file
Xamarin - Entity Framework - SqLite : unable to open database file
In Visual studio 2017, I created a Cross-Platform Mobile App (Xamarin.Forms)
NETStandard 2.0
Microsoft.Data.Sqlite.Core 2.2.0
Microsoft.EntityFrameworkCore 2.2.0
Microsoft.EntityFrameworkCore.Sqlite 2.2.0
Microsoft.EntityFrameworkCore.Tools 2.2.0
I did a code first migration to Sqlite with Entity Framework. All tables are created successfully. The database was seeded.
When I try to get the ItemsViewModel (see code below), I get the following exception (after 20 seconds) on the line --> List item list1 = await db.Person.ToListAsync();
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'. at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db) at Microsoft.Data.Sqlite.SqliteConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
Strangely enough my method TestSqLiteDataStoreAsync (see code below) correctly returns the expected list of items.
Below you will find the relevant code. If you need anything more, let me know.
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ItemsPage : ContentPage
{
ItemsViewModel viewModel;
public ItemsPage()
{
InitializeComponent();
//1 code starts here
BindingContext = viewModel = new ItemsViewModel();
}
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
var item = args.SelectedItem as Item;
if (item == null)
return;
await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));
ItemsListView.SelectedItem = null;
}
async void AddItem_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
}
//adding 'async' did not solve the problem
protected async override void OnAppearing()
{
base.OnAppearing();
if (viewModel.Items.Count == 0)
//2 code continues here
viewModel.LoadItemsCommand.Execute(null);
}
}
public class ItemsViewModel : BaseViewModel
{
public ObservableCollection<Item> Items { get; set; }
public Command LoadItemsCommand { get; set; }
public ItemsViewModel()
{
Title = "Browse";
Items = new ObservableCollection<Item>();
//3 code continues here
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
{
var newItem = item as Item;
Items.Add(newItem);
await DataStore.AddItemAsync(newItem);
});
}
//My test method
public async Task<List<Item>> TestSqLiteDataStoreAsync()
{
SqLiteDataStore SqLiteDataStore = new SqLiteDataStore();
return await SqLiteDataStore.GetItemsAsync(false);
}
async Task ExecuteLoadItemsCommand()
{
if (IsBusy)
return;
IsBusy = true;
try
{
Items.Clear();
//4 code continues here
var items = await DataStore.GetItemsAsync(true);
foreach (var item in items)
{
Items.Add(item);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
finally
{
IsBusy = false;
}
}
}
public class SqLiteDataStore : IDataStore
{
public string dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public string fileName = "TestSqLite.db";
public SqLiteDataStore() { }
public async Task<List<Item>> GetItemsAsync(bool forceRefresh = false)
{
try
{
using (var db = new Models.MyContext(Path.Combine(dbFolder, fileName)))
{
List<Person> list1 = new List<Person>();
List<Item> list2 = new List<Item>();
//5 I get the error here
list1 = await db.Person.ToListAsync();
foreach (Person person in list1)
{
Item item = new Item(person);
list2.Add(item);
}
return list2;
}
}
catch (Exception)
{
throw;
}
}
public async Task<bool> AddItemAsync(Item item)
{
throw new NotImplementedException();
}
public Task<bool> UpdateItemAsync(Item item)
{
throw new NotImplementedException();
}
public Task<bool> DeleteItemAsync(string id)
{
throw new NotImplementedException();
}
public Task<Item> GetItemAsync(string id)
{
throw new NotImplementedException();
}
}
TouchView | TouchImage | TouchFadeView | TouchColorView package
Hi all, let me introduce new plugin for Xamarin.Forms development.
https://github.com/AndreiMisiukevich/TouchEffect
This plugin allows developers to create UI-responsive controls/layouts with touch effect (fade control, change image source, change background color)
I will appreciate any feedback)
How to set Width and Height to 'Entry' tag for platform specifics.
we want to Change Width and Height of Entry
tag in XAML file with platform specifics.
to Change width , i am going with below process-
<Entry>
Entry.Width> <OnPlatform x:TypeArguments="GridLength"> <On Platform="iOS">8*</On> <On Platform="Android">9*</On> </OnPlatform> </Entry.Width>
</Entry>
But i getting below error during project build -
Error Position 31:26. No property, bindable property, or event found for 'Width'
is it possible to set width and Height to Entry tag with platform specifics?
Get image thumbnail from a video file.
Hey, I tried a lot of tutorials and some of the NuGet packages (most of them are not free, instead I need a free one) and yet I failed to find a solution for this "get thumbnail from a video file in Xamarin (or c#)", so can anyone provide me a solution on how to create a thumbnail image from a video file (when pick existing video or take a new one), it would be much appreciated.
Background Color Transparent is not working in GroupHeaderTemplate of Listview in Xamarin Forms iOS
I have set background image for whole application,
In Listview, GroupHeaderTemplate Background color set 'Transparent', but it displays white only.
In Android it's working properly. Anyone knows the solution ?
Firebase device token on Xamarin.Forms
I asked this question 17 hours ago on stackoverflow but sadly no one replied.
I have a Xamarin.Forms project and I'm using the firebase messaging platform to provide push notifications to my app. The last step that is stopping me from publishing the app is the lack of _FirebaseInstanceId _Nuget for xamarin.forms which seems to exist only for xamarin.android. The reason behind why it is so important for my project is getting the cloud messaging token. From what I've seen throughout internet forums it wasn't covered clearly what to do in this situation.
The notifications in my app work in an unusual way. The user chooses one of around 30 options, and then depending on his choice he receives appropriate push notification. So I've written a script that sends his choice to the firebase database and that is where his token is required so a javascript server connected to firebase could send him the push.
I hope I made it clear, and that that the solution wasn't covered previously on this forum. I'm still a beginner so a detailed solution or some suggestions would be really appreciated.
Text to speech is not read when navigate to other screen or click on back button in Xamarin forms
Hi Guys,
I am Implemented Text to speech functionality using Xamarin forms Essentials package, Text to speech is not read when we navigate to other screen or click on back button.
I have 5 pages in my Application, suppose I am in SecondPage before reading speech content in the Second page when i navigate to third page or press back button Text to Speech is not working.
Can anyone help on this.
Thanks,
Srinivasu
How to deserialize json Using Newtonsoft?
I am new to Xamarin and don't have muh knowlwdge on json parsing. Please anyone suggest me how to deserialize the below json, so that I can get all bill object. I wrote C# code like this, but getting error
public class Bills
{
public string status { get; set; }
public IList bill { get; set; }
public async static Task<List<Bill>> GetBills()
{
List<Bills> bills = new List<Bills>();
Uri uri = new Uri(Constants.Bills_URL);
using (HttpClient client = new HttpClient())
{
var response = await client.GetAsync(uri);
var content = await response.Content.ReadAsStringAsync();
bills = JsonConvert.DeserializeObject<Bills>(content);
}
return bills;
}
}
This is the json, that i want to deserialize
{
"status": "success",
"bill": [
{
"bill_id": "1",
"transaction_date": "2018-04-01 06:00:00",
"billing_date": "2018-04-01",
"vehicle_id": "1",
"customer_id": "2",
"fuel_id": "1",
"fuel_unit_id": "1",
"fuel_price_id": "1",
"price_per_unit": "69.97",
"quantity": "12732.27",
"amount": "890877.00",
"received_amount": "0.00",
"advance_amount": "0.00",
"net_amount": "890877.00",
"status": "success",
"station_id": "1",
"customer_name": "Anerr",
"vehicle_number": "TS 30 T 1157",
"fuel_name": "Diesel",
"station_name": "HSDrtr I"
},
{
"bill_id": "2",
"transaction_date": "2018-04-01 06:00:00",
"billing_date": "2018-04-01",
"vehicle_id": "2",
"customer_id": "1",
"fuel_id": "1",
"fuel_unit_id": "1",
"fuel_price_id": "0",
"price_per_unit": "69.97",
"quantity": "10793.31",
"amount": "755208.00",
"received_amount": "0.00",
"advance_amount": "0.00",
"net_amount": "755208.00",
"status": "success",
"station_id": "2",
"customer_name":"Sangram",
"vehicle_number": "dff 6558",
"fuel_name": "Diesel",
"station_name": "HSDff II"
}
]
How do I change the text lineheight?
Hi guys,
I'm trying to change the lineheight of a label but I couldn't figure it out. Can somebody help me out?
Xamarin form : App crash after splash activity
i have splash screen when i run my app its crash. Here is my splash screen code
if i dont use splash screen app is working fine but when i use splash screen and close my app and run again its crash after splash screen
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var mainIntent = new Intent(Application.Context, typeof(MainActivity));
if (Intent.Extras != null)
{
mainIntent.PutExtras(Intent.Extras);
}
mainIntent.SetFlags(ActivityFlags.SingleTop);
StartActivity(mainIntent);
}
}
Recommend beautiful template
Hi All
I am would like to build a mobile app on Xamarin and back-end on web application. Could you share me some of beautiful template that I can buy for my mobil app, and also back-end web-app?
Thanks in advance
Can someone help in creating a Modbus TCP client for Xamarin.iOS and Xamarin.Android ?
I am pretty new to Xamarin. How do I build a Modbus TCP client that will connect to a server host and read a few registers? Any help is much appreciated.
Tapping on Entry in ListView doesn't select the ListView row
I have a Label and an Entry in a ListView, however, when I tap any given Entry in the ListView, it does not select the ListView row that contains that tapped Entry. When I tap a Label, the selected ListView row is correctly changed. Is there a known workaround for this? I need the selected ListView row to change to the row containing the Entry that receives focus.
Unit testing FFImageLoading and calling CachedImageRenderer.Init?
I am trying to create unit test that calls methods that are dependent of FFImageLoading.Forms.CachedImage
. I get this exception:
System.Exception: Please call CachedImageRenderer.Init method in a platform specific project to use FFImageLoading!
How can I call this method from a test project? Will I have to create platform specific code snippet that calls init? Or is there any other way around it?