date Picker Dialog in android

package com.datepic;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatepicActivity extends Activity {
//initializing an integer with some value
int Datepic=1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// This method is used to show the date picker which has an integer type parameter

showDialog(Datepic);

}
});

}
protected Dialog onCreateDialog(int id)
{

//creating the calender instance to get the current date,dateofmonth and year. This is used to set current time for the date picker

 
Calendar c=Calendar.getInstance();
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH);
int day=c.get(Calendar.DATE);

return new DatePickerDialog(DatepicActivity.this, mdate, year, month, day);

}

 

//setting an

DatePickerDialog.OnDateSetListener mdate=new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub

TextView tv1=(TextView) findViewById(R.id.tv);
String s1,s2,s3;
s1=Integer.toString(dayOfMonth);
s2=Integer.toString(monthOfYear+1);
s3=Integer.toString(year);
tv1.setText(s1+”-“+s2+”-“+s3);

}
};


}

Advertisements

Simple notification in Android

package com.notification;

 

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

 

public class NotificationActivity extends Activity {

private NotificationManager manager;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

       Notification notifydetails=new Notification(R.drawable.ic_launcher, “new alert”, System.currentTimeMillis());

       Intent i=new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(“http://www.google.com”));

       

       PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, i, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

       notifydetails.setLatestEventInfo(getApplicationContext(), “title”, “this is text”, pi);

       manager.notify(0, notifydetails);

        

        

    }

}

 

when we click on the button it navigates to the browser and loads the url given with the implicit intent.