Monday, 30 November 2015

Sunday, 29 November 2015

schedule a repeating task

timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask() {

        synchronized public void run() {

            \\ here your todo;
            }

        }}, 60000, 60000);
 
 
http://stackoverflow.com/questions/14376470/scheduling-recurring-task-in-android
 
timer = new Timer();
TimerTask task = new TimerTask(){

    @Override    public void run() {
        new GetJson().execute(url);
    }

};
long whenToStart = 5*1000L; // 5 secondslong howOften = 5*1000L; // 5 secondstimer.scheduleAtFixedRate(task, whenToStart, howOften); 

heads up notification 2

private void showNotification(boolean showAsHeadsUp)
{
    final Intent intent = getIntent();
    intent.putExtra("launched_from_notification", true);

    final Notification.Builder nb = new Notification.Builder(this);
    nb.setContentTitle("Foobar");
    nb.setContentText("I am the content text");
    nb.setOngoing(true);
    nb.setSmallIcon(android.R.drawable.ic_dialog_info);
    nb.setContentIntent(PendingIntent.getActivity(
            this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
    nb.setPriority(Notification.PRIORITY_HIGH);

    // Notifications without sound or vibrate will never be heads-up    nb.setDefaults(showAsHeadsUp ? Notification.DEFAULT_ALL : 0);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(0, nb.build());
}

heads up notification

private void showHeadsUpNotification()
{
    final Notification.Builder nb = new Notification.Builder(this);
    nb.setContentTitle("Foobar");
    nb.setContentText("I am the content text");
    nb.setDefaults(Notification.DEFAULT_ALL);
    nb.setOngoing(true);
    nb.setSmallIcon(android.R.drawable.ic_dialog_info);
    nb.setContentIntent(PendingIntent.getActivity(this, 0, getIntent(), 0));

    // Commenting this line 'fixes' it by not making it heads-up, but that's    // not what I want...    nb.setPriority(Notification.PRIORITY_HIGH);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(0, nb.build());
}

Saturday, 28 November 2015

delay any event in android

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    //Do something after 100ms
  }
}, 100);