private System.Timers.Timer _timer;
private int _countSeconds;
void Main()
{
_timer = new System.Timers.Timer();
//Trigger event every second
_timer.Interval = 1000;
_timer.Elapsed += OnTimedEvent;
//count down 5 seconds
_countSeconds = 5;
_timer.Enabled = true;
}
private void OnTimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
_countSeconds--;
//Update visual representation here
//Remember to do it on UI thread
if (_countSeconds == 0)
{
_timer.Stop();
}
}
Wednesday, 2 April 2014
How to create CountDown Timer in Xamarin Android?
Wednesday, 30 October 2013
How to create AsyncTask in Xamarin Android?
//here is code for AsyncTask perform long running background operation in Android.
public class BackGroundTask : AsyncTask
{
private ProgressDialog _progressDialog;
public BackGroundTask(Context context)
{
_context = context;
}
protected override void OnPreExecute()
{
base.OnPreExecute();
_progressDialog = ProgressDialog.Show(_context, " Progressing", "Please wait...");
}
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
{
}
protected override void OnPostExecute(Java.Lang.Object result)
{
base.OnPostExecute(result);
_progressDialog.Hide();
}
public class BackGroundTask : AsyncTask
{
private ProgressDialog _progressDialog;
public BackGroundTask(Context context)
{
_context = context;
}
protected override void OnPreExecute()
{
base.OnPreExecute();
_progressDialog = ProgressDialog.Show(_context, " Progressing", "Please wait...");
}
protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
{
}
protected override void OnPostExecute(Java.Lang.Object result)
{
base.OnPostExecute(result);
_progressDialog.Hide();
}
How to launch Facebook app through Xamarin Android ?
here if facebook is not installed on your divice then it will redirect to web browser.
public void getFacebook(){
bool result=isAppInstalled("com.facebook.katana");
if(result)
{
string v = FB_URL.Replace("https", "fb");
var uri = Android.Net.Uri.Parse (v);
var intent = new Intent (Intent.ActionView, uri);
StartActivity(intent);
}
else
{
StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse(FB_URL)));
}
}
protected bool isAppInstalled(string packageName)
{
Intent mIntent = PackageManager.GetLaunchIntentForPackage(packageName);
if (mIntent != null)
{
return true;
}
else
{
return false;
}
}
Friday, 1 February 2013
How to move cursor right side in edit text android ?
// this code will help you to move
private mEditext;
int cursorPos =mEditext.getSelectionStart();
cursorPos--;
if (cursorPos<0) cursorPos=0;
mEditext.setSelection(cursorPos);
Tuesday, 29 January 2013
How to send Email with Attachment Android
// put this code on your on button click
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"wadghanednyaneshwar@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/example.txt"));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "gmail.com");
MainActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"wadghanednyaneshwar@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/example.txt"));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "gmail.com");
MainActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Subscribe to:
Posts (Atom)