xamarin ios culture not found by identifier - xamarin

I'm using xamarin ios including following system library
https://www.nuget.org/packages/System.Globalization/4.3.0
I'm getting device current language- region from preferred languages and trying to create Culture info from it:
var deviceLang = NSLocale.PreferredLanguages[0];
var info = CultureInfo.CreateSpecificCulture(deviceLang);
if device returns for example "en-CH" culture info says then he doesn't support such configuration and returns "en-US" culture. if you will search in microsoft documentation you will find such configuration as supported one . Also, to create NSLocale from this identifier is okay:
var loc = new NSLocale("en-CH");
var dd = loc.Identifier; // returns en-CH
Do you have any idea why xamarin.ios doesn't support such culture ? p.s. system.globalization dll is up to date.

Related

How to access mobile data usage from settings in android mobile using xamarin forms

In my application i want to access contact names and mobile data usage from Android mobile. I get the contacts list from the mobile by using the below code. But I have no idea how to access mobile data usage from the settings in android mobile. I have referred many sites but none of them could give me a clear answer. How do I access the mobile data usage when mobile data is turned ON?
var context = MainActivity.GetAppContext();
var uri = ContactsContract.Contacts.ContentUri;
string[] projection = { ContactsContract.Contacts.InterfaceConsts.Id,
ContactsContract.Contacts.InterfaceConsts.DisplayName,
ContactsContract.Contacts.InterfaceConsts.HasPhoneNumber
};
var cursor = context.ContentResolver.Query(uri, projection, null, null, null);
ObservableCollection<UserContact> UserContactList = new
ObservableCollection<UserContact>();
cursor.MoveToFirst();
You can query only basic info using the Android.Net.TrafficStats class:
var receivedTotal = Android.Net.TrafficStats.MobileRxBytes;
var transmittedTotal = Android.Net.TrafficStats.MobileTxBytes;
//app-specific
var uid = Android.OS.Process.MyUid();
var receivedByApp = Android.Net.TrafficStats.GetUidRxBytes(uid);
var transmittedByApp = Android.Net.TrafficStats.GetUidTxBytes(uid);
Please note that the app-specific methods return overall number of bytes since the network interface or app started and may be zeroed-out when connection drops or app closes. Also they count not only mobile data, but include wi-fi connection as well.
There is no built-in API to query mobile data usage of other apps in the default API. Some manufacturers might offer their own implementations for this, but it is not available in the "clean Android OS".

Open Native iOS app from Xamarin.Forms

I have an native iOS sample app installed in my iPad and also my sample xamarin.Forms App installed. I want to open native iOS app from Xamarin.forms when clicked on button. I have set URL schema in my native iOS app in info.plist.
How do I open native app from xamarin.forms on click of a button. I already tried
var request = Device.OnPlatform(
string.Format("native app url"),
string.Format("native app url"),
string.Format("native app url"));
Device.OpenUri(new Uri(request));
but its not working.
It's basically how you are doing it.
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Device.OpenUri(new Uri(request));
Be aware that each platform have some requirements in the way to url is configured and parameters are sent.
Let say to get the maps app open in each platform you would use these urls schemes:
// iOS doesn't like %s or spaces in their URLs, so manually replace spaces with +s
var iOSUrl = string.Format("http://maps.apple.com/maps?q={0}&sll={1}", name.Replace(' ', '+'), loc);
var androidUrl = string.Format("geo:0,0?q={0}({1})", string.IsNullOrWhiteSpace(addr) ? loc : addr, name);
var winPhoneUrl = $"bingmaps:?cp={loc}&q={name}";
var url = Device.OnPlatform(iOSUrl, androidUrl, winPhoneUrl);
Also you cannot open any arbitrary app unless you know its Url scheme.
Anyway, if the Device.OpenUri() doesn't fulfill your requirements you are good to create your own implementations using the native APIs.
Please go through the below link and attached photo
Link:-launch-an-app-from-within-another-iphone
I am using below code in xamarin forms
NSUrl request = new NSUrl("Camera://");
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(request.ToString()));
if (!canOpen)
{ Task.FromResult(false); }
else
{
Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(request.ToString())));
}

How can i use internal database from scratch

How can i using internal database for example (sqlite) for offline app in nativescript without using any plugin.
i'm searched every were how i can installed or used sqlite or other internal database for nativescript but i didn't have any answer.
Just like you would do with any code that you need to access the native APIs
e.g. (JavaScript) Android example
var query = "select sqlite_version() AS sqlite_version";
var db = android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(":memory:", null);
var cursor = db.rawQuery(query, null);
var sqliteVersion = "";
if (cursor.moveToNext()) {
sqliteVersion = cursor.getString(0);
console.log(sqliteVersion);
}
The API references for SQLite in Android here and that said you can now follow a basic Android database tutorial and implement it step by step in your NativeScript application using JavaScript or TypeScript
Still, the plugin could provide all that wrapped in a ready-to-go functionality so unless you are lacking something it will be easier to use the nativescript-sqlite and avoid writing native code for Android and then for iOS.

Get mac address and ip in Nativescript

We are implementing a server for app distribution and we need restrict the access to the apps by:
mac address
ip
At the moment I have not found any module that can obtain this data from the device in nativescript, so i don't know if there's a plugin or how else can I achieve this.
In nativescript you can access native apis of device
so if there isn't any module/plugin for it you can use this option for accessing native apis.
https://docs.nativescript.org/core-concepts/accessing-native-apis-with-javascript
for example there is solution for mac adress here
in JAVA:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String mac = wInfo.getMacAddress();
we can write it in javascript like this:
first we should fine where is this getSystemService:
after searching in documentation of android we found:
getSystemService is in android.content.Context
for accessing context in nativescript http://docs.nativescript.org/cookbook/application
we can do:
import app = require("application");
app.android.context;
so let's write it in javascript:
we don't have types in javascript so we use var instead;
var context = android.content.Context;
var wifiManager = app.android.context.getSystemService(context.WIFI_SERVICE);
var wInfo = wifiManager.getConnectionInfo();
var mac = wInfo.getMacAddress();
NOTE1 : as mentioned in above java solution link you should add this permision <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> to app/App_Resources/AndroidManifest
NOTE2 : the above solution was for android,for ios you should find the solution with objective_c and convert to javascript with help of nativescript documentation.
NOTE3:In android 6 you might need request permision
You can also use this method to create a plugin for nativescript.

How to set UI language in code for Windows Phone application?

Let's say my application doesn't support culture es-MX so when this is the current setting on the phone I'd like to set the culture to es-ES. Is this possible to do in Windows Phone and if so how?
This is definitely possible!
See this list for cultures and their identifiers
So for example in the App.xaml.cs constructor you could access Thread.CurrentThread.CurrentCulture to determine the actual culture the app is running in. Now if you want to force the UI to use another culture you can do that by setting the CurrentUICulture. For example:
if (Thread.CurrentThread.CurrentCulture.Name.Equals("es-MX"))
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");
}

Resources