Wednesday 27 June 2012

CountDownTimer in andriod


class timess extends CountDownTimer {
public timess(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}

@Override
public void onFinish() {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "hello", 10000).show();
}
//on Tick method is call Every time
@Override
public void onTick(long millisUntilFinished) {
delay = delay + 1;
if (delay > 3) {
second = second + 1;
}
if (second == 60) {
minute = minute + 1;
second = 0;
}

// TODO Auto-generated method stub
}
}

How to call Countdown timmer class in activity...........


"timess" is the name of that class which is extend by countdowntimer 



timess tm = new timess(1000000000, 1000);
tm.start();



Services in andriod


public class Myserviceclass extends Service {
private static final String TAG = "MyService";

double d;
public String mPhoneNumber, loc, unicode, datalatitute, datalognitute,
dataunicode, datatiming, timming, ourNumber, sDeviceID, phnno,
mint, hr, sec, Answer_id;
int Dataid, countQuestion = 1, second = 0, minute = 0, hours = 0,
delay = 0, quesno = 2;
double latitude, longitude, datalognitute1, datalatitute1;
// ParsingN pn;
Timer t;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {

Log.d(TAG, "onCreate");
}
// Start method is call.................Every time when service is run in back ground
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
}

@Override
public void onStart(Intent intent, int startid) {

Log.d(TAG, "onStart");



LocationManager locationmanager = (LocationManager)                     getSystemService(Context.LOCATION_SERVICE);
Location location2 = locationmanager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.i("ccc", "" + location2);
Location location1 = locationmanager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location1 != null) {
latitude = location1.getLatitude();
longitude = location1.getLongitude();
Log.d("testing1111", "" + latitude + "kkk" + longitude);
loc = "" + longitude + "+" + "" + latitude;
} else {
Log.d("testing1111", "testing fail");
}

Toast.makeText(getApplicationContext(), "" + loc, 20000).show();
// //////// GETTING UNIQUE CODE AND PHONE NO FROM WEBSERVICE
if (Geocoder.isPresent()) {
/*Getparsing obj = new Getparsing(
"http://192.168.3.24/phpnewebservice/phonewebservice.php?user=1");*/
Getparsing obj = new Getparsing(
"http://192.168.3.24/phpnewebservice/phonewebservice.php?user=1");
Log.i("kkkk", "" + Geocoder.isPresent());
} else {
Toast.makeText(getApplicationContext(), "wait......",
Toast.LENGTH_LONG).show();
}
Log.i("karan11", "soni");
Log.i("karan222", "soni");
SitesList sitesList = new SitesList();
sitesList = MyXMLHandler.sitesList;
Log.i("size", "" + sitesList.getPhn_ID().size());
for (int i = 0; i < sitesList.getPhn_no().size(); i++) {
Log.i("getting no", "" + sitesList.getPhn_no().get(i));
}
for (int i = 0; i < sitesList.getPhn_ID().size(); i++) {
Log.i("getting id", "" + sitesList.getPhn_ID().get(i));
}
for (int i = 0; i < sitesList.getCode().size(); i++) {
Log.i("getting c", "" + sitesList.getCode().get(i));
}
TelephonyManager mTelephonyMgr = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
ourNumber = mTelephonyMgr.getLine1Number();
sDeviceID = mTelephonyMgr.getDeviceId();
int N = sitesList.getPhn_no().indexOf(ourNumber);
int PID = sitesList.getPhn_ID().indexOf(sDeviceID);
unicode = sitesList.getCode().get(PID);
Log.i("NN", "" + N);
Log.i("unicode", "" + unicode);
if (Geocoder.isPresent()) {

Log.i("kkkk", "" + Geocoder.isPresent());
}
if (!Geocoder.isPresent()) {

Log.i("kkkk", "" + Geocoder.isPresent());

}
}


}

Tuesday 12 June 2012

how to send message or ACTION_SENDTO


Uri uri = Uri.parse("smsto:"+mainArrayList_phno.get(position));  
   Intent it = new Intent(Intent.ACTION_SENDTO, uri);  
   it.putExtra("sms_body", ""+password);  
   startActivity(it);

how to get CONTENT no. from phone


Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
 String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
 String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
 name_array_list.add(name);
 phone_no_array_list.add(phoneNumber);
}
phones.close();

how to draw line between two latitude and two lognitute


public class Route_mapActivity extends MapActivity {

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

private List mapOverlays;
private Projection projection;
private MapController mc;
private MapView mapView;
private GeoPoint gP;

// private GeoPoint gP2;

private MyOverlay myoverlay;
double my_Latitude, friend_latitude;
double my_Longitude, friend_Longitude;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);// Creating an instance
// of MapView
mapView.setBuiltInZoomControls(true);// Enabling the built-in Zoom
// Controls
gP = new GeoPoint(33695043, 73000000);// Creating a GeoPoint
mc = mapView.getController();
mc.setCenter(gP);
mc.setZoom(9);// Initializing the MapController and setting the map to
// center at the

// defined GeoPoint
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
myoverlay = new MyOverlay();
mapOverlays.add(myoverlay);

}

@Override
protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub

return false;

}

class MyOverlay extends Overlay {

public MyOverlay() {
}

public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas, mapv, shadow);
// Configuring the paint brush

Point screenPts = new Point();
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(4);

my_Latitude = getIntent().getExtras().getDouble("my_Latitude");
my_Longitude = getIntent().getExtras().getDouble("my_Longitude");
friend_latitude = getIntent().getExtras().getDouble("friend_lati");
friend_Longitude = getIntent().getExtras().getDouble("friend_longni");

Log.e("my_Latitude1E6", "" + ((int) (my_Latitude * 1000000)));
GeoPoint gP1 = new GeoPoint((int) (my_Latitude * 1000000),
((int) my_Longitude * 1000000));// starting point Abbottabad
GeoPoint gP2 = new GeoPoint(
(int) (friend_latitude * 1000000 + 1000000),
((int) friend_Longitude * 1000000 + 1000000));// End point
// Islamabad

Point p1 = new Point();
Point p2 = new Point();
Path path1 = new Path();
Point p3 = new Point();
Point p4 = new Point();
Path path2 = new Path();
projection.toPixels(gP2, p3);
projection.toPixels(gP1, p4);
path1.moveTo(p4.x, p4.y);// Moving to Abbottabad location
path1.lineTo(p3.x, p3.y);// Path till Islamabad
/*
* projection.toPixels(gP3, p1);
*
* projection.toPixels(gP4, p2);
*/
path2.moveTo(p2.x, p2.y);// Moving to Islamabad location
path2.lineTo(p1.x, p1.y);// Path to Rawalpindi
canvas.drawPath(path1, mPaint);// Actually drawing the path from
// Abbottabad to Islamabad
canvas.drawPath(path2, mPaint);// Actually drawing the path from
// Islamabad to Rawalpindi

}

}

}