Posts

Showing posts from June, 2017

How to get device info IMEI programmatically in xamarin android

You'll need the following permission in your  AndroidManifest.xml : <uses-permission android:name="android.permission.READ_PHONE_STATE" /> in order to do this. You want to call  android.telephony.TelephonyManager.getDeviceId() . This will return whatever string uniquely identifies the device (IMEI for GSM, MEID for CDMA). Code Android.Telephony.TelephonyManager mTelephonyMgr;             mTelephonyMgr = (Android.Telephony.TelephonyManager)GetSystemService(TelephonyService);   //IMEI number    String m_deviceId = mTelephonyMgr.DeviceId;

Remove all cookies using jquery

you can download cookies plugin from  https://plugins.jquery.com/cookie/ and use this script var cookies = $ . cookie (); for ( var cookie in cookies ) { $ . removeCookie ( cookie ); }

Java.Lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

Code Toast toast = Toast . makeText ( mContext , "Something" , ToastLength . LENGTH_SHORT ); Exception Java.Lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() Reason Android basically works on two thread types namely UI thread and background thread. Toast cannot be called from a non-UI thread. Solution RunOnUiThread(() => { Toast.MakeText(this, "Something", ToastLength.Short).Show(); });

How Pass Parameter to ThreadStart in C#

There are two ways to accomplish it. 1.  Thread thread = new Thread (() => download ( parm1 )); thread . Start (); 2. Thread thread = new Thread ( new ParametrizedThreadStart ( func1 )); thread. Start (parm 1 );

Create Alert Dialog in Xamarin Android

1. Using AlertDialog in Xamarin.Android AlertDialog  is the subclass of  Dialog  that can display one, two or three buttons. If you only want to display a String in this dialog box, use the  SetMessage()  method. The following code snippet can be used to create a simple AlertDialog with two buttons Delete and Cancel. //set alert for executing the task AlertDialog.Builder alert = new AlertDialog.Builder (this); alert.SetTitle ("Confirm delete"); alert.SetMessage ("Lorem ipsum dolor sit amet, consectetuer adipiscing elit."); alert.SetPositiveButton ("Delete", (senderAlert, args) => { Toast.MakeText(this ,"Deleted!" , ToastLength.Short).Show(); }); alert.SetNegativeButton ("Cancel", (senderAlert, args) => { Toast.MakeText(this ,"Cancelled!" , ToastLength.Short).Show(); }); Dialog dialog = alert.Create(); dialog.Sho...

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

For Windows 7 and Windows Server 2008, use the ASP.NET IIS Registration Tool (aspnet_regiis.exe,) to register the correct version of ASP.NET To register the correct version of ASP.NET On the computer that is running Microsoft Dynamics NAV Web Server components, open a command prompt as an administrator as follows: From the  Start  menu, choose  All Programs , and then choose  Accessories . Right-click  Command Prompt , and then choose  Run as administrator . At the command prompt, type the following command to change to the  Microsoft.NET\Framework64\v4.0.30319  folder, and then press Enter. cd\Windows\Microsoft.NET\Framework64\v4.0.30319 At the command prompt, type the following command, and then press Enter. aspnet_regiis.exe -iru At the command prompt, type the following command, and then press Enter. iisreset

Delete / truncate all the records from solr using url

Clear Solr Core : http://localhost:8983/solr/core/update?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&commit=true

Clear cache programmatically in c#

public override void OnResultExecuting(ResultExecutingContext filterContext) {     filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));     filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);     filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);     filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);     filterContext.HttpContext.Response.Cache.SetNoStore(); }

Converting json into object in c#

Image
Requirement: Newtonsoft.Json c# code: var _result = JsonConvert.DeserializeObject<UserModel>(jsonString);

HttpClient web request HttpGet and HttpPost

HTTPGET Uri mCmpUrl = new Uri("http://www.domain.com/");                  HttpClient oHttpClient = new HttpClient(); oHttpClient.BaseAddress = mCmpUrl; oHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var url = "api/Account?UserId=1"&Password=123"; HttpResponseMessage response = oHttpClient.GetAsync(url).Result; if (response.IsSuccessStatusCode) {    var result = response.Content.ReadAsStringAsync().Result;    var AccModResult = JsonConvert.DeserializeObject<AccMod>(result); } HTTPPOST Uri mCmpUrl = new Uri("http://www.domain.com/Account"); var json = JsonConvert.SerializeObject( obj ); HttpClient oHttpClient = new HttpClient(); var oTaskPostAsync = oHttpClient.PostAsync(mCmpUrl, new StringContent(json, Encoding.UTF8, "application/json")); oTaskPostAsync.ContinueWith((oHttpResponseMessage) => {          ...

Difference between Encapsulation and Abstraction

Encapsulation reduce complexity hide the information which you don't want to share with outside world In simple word encapsulation is information hiding              Abstraction Show only the essential features hide internal process In simple word abstraction is implementation hiding Example (Console Program)     class CustomerClass     {         public void AddCustomer(string name)         {             validate("uttam");             savedata("uttam");         }         private bool validate(string name)         {             //Validate name             return true;         }         private bool savedata(string name)     ...