public async Task <bool> SendPicItemAsync(PicItem item) { if (item == null || !CrossConnectivity.Current.IsConnected) { return(false); } string mPhoneNumber = ""; var ctx = Forms.Context; Android.Telephony.TelephonyManager tMgr = (Android.Telephony.TelephonyManager)ctx.GetSystemService(Android.Content.Context.TelephonyService); mPhoneNumber = tMgr.Line1Number; HttpClientHandler handler = new HttpClientHandler(); using (var client = new HttpClient(handler, true)){ client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Add("Token-Number", mPhoneNumber); //replace with mPhoneNumber client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //var uri = new Uri(string.Format(App.BackendUrl, string.Empty)); var uri = new Uri(string.Format(App.BackendUrl + "/server/insert_data/")); var json = JsonConvert.SerializeObject(item); var content = new StringContent(json, Encoding.UTF8, "application/json"); var resp = await client.PostAsync(uri, content); string jsonString = await resp.Content.ReadAsStringAsync(); Response response = JsonConvert.DeserializeObject <Response>(jsonString); return(response.status == 200); } }
public async Task <IEnumerable <ST> > GetSTItemsAsync(bool forceRefresh = false) { string mPhoneNumber = ""; var ctx = Forms.Context; Android.Telephony.TelephonyManager tMgr = (Android.Telephony.TelephonyManager)ctx.GetSystemService(Android.Content.Context.TelephonyService); mPhoneNumber = tMgr.Line1Number; using (var client = new HttpClient()) { var uri = new Uri(string.Format(url, string.Empty)); //System.Diagnostics.Debugger.Break(); client.DefaultRequestHeaders.Add("Token-Number", mPhoneNumber); var response = await client.GetAsync(uri + "server/getSTFolios/"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var Item = JsonConvert.DeserializeObject <List <ST> >(content); return(Item); } return(new List <ST>()); } }
public string GetIMEI() { Android.Telephony.TelephonyManager mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService); if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { // TODO: Some phones has more than 1 SIM card or may not have a SIM card inserted at all return(mTelephonyMgr.GetMeid(0)); } else #pragma warning disable CS0618 // Type or member is obsolete { return(mTelephonyMgr.DeviceId); } #pragma warning restore CS0618 // Type or member is obsolete }
public static bool IsIntentAvailable(Context context, Intent intent) { var packageManager = context.PackageManager; var list = packageManager.QueryIntentServices(intent, 0) .Union(packageManager.QueryIntentActivities(intent, 0)); if (list.Any()) { return(true); } Android.Telephony.TelephonyManager mgr = Android.Telephony.TelephonyManager.FromContext(context); return(mgr.PhoneType != Android.Telephony.PhoneType.None); }
protected string GetTelephoneId() { Android.Telephony.TelephonyManager tm = GetSystemService <Android.Telephony.TelephonyManager>(Android.Content.Context.TelephonyService); return(tm.DeviceId); }
public string DeviceIdIMEI() { Context = Android.App.Application.Context; telephony_manager = (Android.Telephony.TelephonyManager) Context.GetSystemService(Android.Content.Context.TelephonyService); return telephony_manager.DeviceId; }
public string PhoneNumber() { telephony_manager = (Android.Telephony.TelephonyManager) Context.GetSystemService(Android.Content.Context.TelephonyService); return telephony_manager.Line1Number; }
public string GetIdentifier() { mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Context.TelephonyService); return(mTelephonyMgr.DeviceId); }
string getInfosFromTelephonyManager(Context context) { StringBuilder sb = new StringBuilder(); try { Android.Telephony.TelephonyManager telm = context.GetSystemService(Android.Content.Context.TelephonyService) as Android.Telephony.TelephonyManager; if (telm != null) { if (!string.IsNullOrEmpty(telm.Line1Number)) { sb.AppendLine(getItemString("Line1Number", telm.Line1Number, NAME1POS, CONTENT1POS)); // Returns the phone number string for line 1, for example, the MSISDN for a GSM phone for a particular subscription. Return null if it is unavailable. } sb.AppendLine(getItemString("PhoneType", telm.PhoneType.ToString(), NAME1POS, CONTENT1POS)); // Returns a constant indicating the device phone type. This indicates the type of radio used to transmit voice calls. sb.AppendLine(getItemString("PhoneCount", telm.PhoneCount.ToString(), NAME1POS, CONTENT1POS)); // Returns the number of phones available. Returns 0 if none of voice, sms, data is not supported Returns 1 for Single standby mode (Single SIM functionality). Returns 2 for Dual standby mode (Dual SIM functionality). Returns 3 for Tri standby mode (Tri SIM functionality). if (!string.IsNullOrEmpty(telm.Imei)) { sb.AppendLine(getItemString("Imei", telm.Imei, NAME1POS, CONTENT1POS)); // Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not available. } if (!string.IsNullOrEmpty(telm.Meid)) { sb.AppendLine(getItemString("Meid", telm.Meid, NAME1POS, CONTENT1POS)); // Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. } sb.AppendLine(""); if (!string.IsNullOrEmpty(telm.SubscriberId)) { sb.AppendLine(getItemString("SubscriberId", telm.SubscriberId, NAME1POS, CONTENT1POS)); // Returns the unique subscriber ID, for example, the IMSI for a GSM phone. } sb.AppendLine(getItemString("SimState", telm.SimState.ToString(), NAME1POS, CONTENT1POS)); // Returns a constant indicating the state of the default SIM card. if (!string.IsNullOrEmpty(telm.SimSerialNumber)) { sb.AppendLine(getItemString("SimSerialNumber", telm.SimSerialNumber, NAME1POS, CONTENT1POS)); // Returns the serial number of the SIM, if applicable. } if (!string.IsNullOrEmpty(telm.SimOperatorName)) { sb.AppendLine(getItemString("SimOperatorName", telm.SimOperatorName, NAME1POS, CONTENT1POS)); // Returns the Service Provider Name (SPN). } if (!string.IsNullOrEmpty(telm.SimOperator)) { sb.AppendLine(getItemString("SimOperator", telm.SimOperator, NAME1POS, CONTENT1POS)); // Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. 5 or 6 decimal digits. } if (!string.IsNullOrEmpty(telm.SimCountryIso)) { sb.AppendLine(getItemString("SimCountryIso", telm.SimCountryIso, NAME1POS, CONTENT1POS)); // Returns the ISO-3166-1 alpha-2 country code equivalent for the SIM provider's country code. } if (!string.IsNullOrEmpty(telm.SimCarrierIdName)) { sb.AppendLine(getItemString("SimCarrierIdName", telm.SimCarrierIdName, NAME1POS, CONTENT1POS)); // Returns carrier id name of the current subscription. } sb.AppendLine(getItemString("SimCarrierId", telm.SimCarrierId.ToString(), NAME1POS, CONTENT1POS)); // Returns carrier id of the current subscription. The carrier ID is an Android platform-wide identifier for a carrier. sb.AppendLine(""); sb.AppendLine(getItemString("NetworkType", telm.NetworkType.ToString(), NAME1POS, CONTENT1POS)); // Return the current data network type. if (!string.IsNullOrEmpty(telm.NetworkSpecifier)) { sb.AppendLine(getItemString("NetworkSpecifier", telm.NetworkSpecifier.ToString(), NAME1POS, CONTENT1POS)); // Returns the network specifier of the subscription ID pinned to the TelephonyManager. } if (!string.IsNullOrEmpty(telm.NetworkOperatorName)) { sb.AppendLine(getItemString("NetworkOperatorName", telm.NetworkOperatorName, NAME1POS, CONTENT1POS)); // Returns the alphabetic name of current registered operator. } if (!string.IsNullOrEmpty(telm.NetworkOperator)) { sb.AppendLine(getItemString("NetworkOperator", telm.NetworkOperator, NAME1POS, CONTENT1POS)); // Returns the numeric name (MCC+MNC) of current registered operator. } if (!string.IsNullOrEmpty(telm.NetworkCountryIso)) { sb.AppendLine(getItemString("NetworkCountryIso", telm.NetworkCountryIso, NAME1POS, CONTENT1POS)); // Returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of the current registered operator or the cell nearby, if available. } if (!string.IsNullOrEmpty(telm.Nai)) { sb.AppendLine(getItemString("Nai", telm.Nai, NAME1POS, CONTENT1POS)); // Returns the Network Access Identifier (NAI). Return null if NAI is not available. } sb.AppendLine(getItemString("IsNetworkRoaming", telm.IsNetworkRoaming.ToString(), NAME1POS, CONTENT1POS)); // Returns true if the device is considered roaming on the current network, for GSM purposes. sb.AppendLine(""); sb.AppendLine(getItemString("DataState", telm.DataState.ToString(), NAME1POS, CONTENT1POS)); // Returns a constant indicating the current data connection state (cellular). sb.AppendLine(getItemString("DataNetworkType", telm.DataNetworkType.ToString(), NAME1POS, CONTENT1POS)); // Returns a constant indicating the radio technology (network type) currently in use on the device for data transmission. DATA_DISCONNECTEDDATA_CONNECTING,DATA_CONNECTED,DATA_SUSPENDED,DATA_DISCONNECTING sb.AppendLine(getItemString("DataEnabled", telm.DataEnabled.ToString(), NAME1POS, CONTENT1POS)); // Returns whether mobile data is enabled or not per user setting. There are other factors that could disable mobile data, but they are not considered here. sb.AppendLine(getItemString("DataActivity", telm.DataActivity.ToString(), NAME1POS, CONTENT1POS)); // Returns a constant indicating the type of activity on a data connection (cellular). DATA_ACTIVITY_NONE,DATA_ACTIVITY_IN,DATA_ACTIVITY_OUT,DATA_ACTIVITY_INOUT,DATA_ACTIVITY_DORMANT sb.AppendLine(""); if (!string.IsNullOrEmpty(telm.MmsUserAgent)) { sb.AppendLine(getItemString("MmsUserAgent", telm.MmsUserAgent, NAME1POS, CONTENT1POS)); // Returns the MMS user agent. } if (!string.IsNullOrEmpty(telm.MmsUAProfUrl)) { sb.AppendLine(getItemString("MmsUAProfUrl", telm.MmsUAProfUrl, NAME1POS, CONTENT1POS)); // Returns the MMS user agent profile URL. } sb.AppendLine(getItemString("IsWorldPhone", telm.IsWorldPhone.ToString(), NAME1POS, CONTENT1POS)); // Whether the device is a world phone. sb.AppendLine(getItemString("IsVoiceCapable", telm.IsVoiceCapable.ToString(), NAME1POS, CONTENT1POS)); // "Voice capable" means that this device supports circuit-switched (i.e. voice) phone calls over the telephony network, and is allowed to display the in-call UI while a cellular voice call is active. This will be false on "data only" devices which can't make voice calls and don't support any in-call UI. sb.AppendLine(getItemString("IsSmsCapable", telm.IsSmsCapable.ToString(), NAME1POS, CONTENT1POS)); // If true, this means that the device supports both sending and receiving sms via the telephony network. sb.AppendLine(getItemString("IsHearingAidCompatibilitySupported", telm.IsHearingAidCompatibilitySupported.ToString(), NAME1POS, CONTENT1POS)); // Whether the phone supports hearing aid compatibility. sb.AppendLine(getItemString("IsConcurrentVoiceAndDataSupported", telm.IsConcurrentVoiceAndDataSupported.ToString(), NAME1POS, CONTENT1POS)); // Whether the device is currently on a technology (e.g. UMTS or LTE) which can support voice and data simultaneously. sb.AppendLine(getItemString("HasIccCard", telm.HasIccCard.ToString(), NAME1POS, CONTENT1POS)); sb.AppendLine(getItemString("HasCarrierPrivileges", telm.HasCarrierPrivileges.ToString(), NAME1POS, CONTENT1POS)); // Has the calling application been granted carrier privileges by the carrier. if (!string.IsNullOrEmpty(telm.GroupIdLevel1)) { sb.AppendLine(getItemString("GroupIdLevel1", telm.GroupIdLevel1, NAME1POS, CONTENT1POS)); // Returns the Group Identifier Level1 for a GSM phone. Return null if it is unavailable. } if (!string.IsNullOrEmpty(telm.DeviceSoftwareVersion)) { sb.AppendLine(getItemString("DeviceSoftwareVersion", telm.DeviceSoftwareVersion, NAME1POS, CONTENT1POS)); // Returns the software version number for the device, for example, the IMEI/SV for GSM phones. Return null if the software version is not available. } sb.AppendLine(""); sb.AppendLine(getItemString("CallState", telm.CallState.ToString(), NAME1POS, CONTENT1POS)); // Returns the state of all calls on the device. sb.AppendLine(getItemString("CanChangeDtmfToneLength", telm.CanChangeDtmfToneLength().ToString(), NAME1POS, CONTENT1POS)); // if (!string.IsNullOrEmpty(telm.VisualVoicemailPackageName)) { sb.AppendLine(getItemString("VisualVoicemailPackageName", telm.VisualVoicemailPackageName, NAME1POS, CONTENT1POS)); // } if (!string.IsNullOrEmpty(telm.VoiceMailAlphaTag)) { sb.AppendLine(getItemString("VoiceMailAlphaTag", telm.VoiceMailAlphaTag, NAME1POS, CONTENT1POS)); // } if (!string.IsNullOrEmpty(telm.VoiceMailNumber)) { sb.AppendLine(getItemString("VoiceMailNumber", telm.VoiceMailNumber, NAME1POS, CONTENT1POS)); // } sb.AppendLine(getItemString("VoiceNetworkType", telm.VoiceNetworkType.ToString(), NAME1POS, CONTENT1POS)); // sb.AppendLine(""); if (telm.SignalStrength != null) { sb.AppendLine(getItemString("SignalStrength", telm.SignalStrength.ToString(), NAME1POS, CONTENT1POS)); // Get the most recent SignalStrength information reported by the modem. Due to power saving this information may not always be current. } if (telm.ServiceState != null) { sb.AppendLine(getItemString("ServiceState", telm.ServiceState.ToString(), NAME1POS, CONTENT1POS)); // Returns the current ServiceState information. } sb.AppendLine(""); foreach (var item in telm.AllCellInfo) { sb.AppendLine(getItemString("CellInfo.CellConnectionStatus", item.CellConnectionStatus.ToString(), NAME1POS, CONTENT1POS)); sb.AppendLine(getItemString("CellInfo.IsRegistered", item.IsRegistered.ToString(), NAME1POS, CONTENT1POS)); TimeSpan ts = new TimeSpan(item.TimeStamp / 100); sb.AppendLine(getItemString("CellInfo.TimeStamp", ts.Days.ToString() + " Tage, " + ts.Hours.ToString() + " Stunden, " + ts.Minutes.ToString() + " Minuten, " + ts.Seconds.ToString() + " Sekunden", NAME1POS, CONTENT1POS)); } } } catch (Exception ex) { sb.AppendLine("Exception: " + ex.Message); } return(sb.ToString()); }