Skip to content

Instantly share code, notes, and snippets.

View mstefanko's full-sized avatar

Mike Stefanko mstefanko

View GitHub Profile
04070f2971bd4f7d211a60dd547453c8dd258a9bb8fb838d0ffd4fd1eaa0a2582e315d6b654fb9028c7f01b0123913a2531b959d64405217d1cba6175ee252d191;nortss
@mstefanko
mstefanko / gist:890601
Created March 28, 2011 14:51
Android links
http://developer.android.com/resources/tu
torials/notepad/index.html - Simple
notepad
http://www.vogella.de/articles/Android/ar
ticle.html - getting started, first
@mstefanko
mstefanko / gist:890465
Created March 28, 2011 13:34
Android sending SMS/MMS programatically
Uri smsUri = Uri.parse("tel:1234567");
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", "Hello frend, How are you?");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
@mstefanko
mstefanko / gist:890458
Created March 28, 2011 13:32
Retrieving postal addresses
String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] addrWhereParams = new String[]{id,
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
Cursor addrCur = cr.query(ContactsContract.Data.CONTENT_URI,
null, where, whereParameters, null);
while(addrCur.moveToNext()) {
String poBox = addrCur.getString(
addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
String street = addrCur.getString(
addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
@mstefanko
mstefanko / gist:890456
Created March 28, 2011 13:32
retrieving notes about contacts
String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] noteWhereParams = new String[]{id,
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null);
if (noteCur.moveToFirst()) {
String note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
}
noteCur.close();
@mstefanko
mstefanko / gist:890454
Created March 28, 2011 13:31
retrieving email addresses
//Querying email addresses is similar to phone numbers. A query must be performed to get email addresses //from the database. Query the URI stored in ContactsContract.CommonDataKinds.Email.CONTENT_URI to query the //email address table.
Cursor emailCur = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses
// if the email addresses were stored in an array
@mstefanko
mstefanko / gist:890453
Created March 28, 2011 13:30
retrieving phone numbers
//retrieving phone numbers
//Phone numbers are stored in their own table and need to be queried separately. To query the phone //number table use the URI stored in the SDK variable ContactsContract.CommonDataKinds.Phone.CONTENT_URI. //Use a WHERE conditional to get the phone numbers for the specified contact.
if (Integer.parseInt(cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
@mstefanko
mstefanko / gist:890450
Created March 28, 2011 13:30
Retrieving contact details
//Basic contact information stored in Contacts table with detailed information stored in individual //tables for normalization. In Android 2.0 to query the base contact records the URI to query is stored //in ContactsContract.Contacts.CONTENT_URI.
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
@mstefanko
mstefanko / gist:890446
Created March 28, 2011 13:27
Distence calculation between two GPS points
private double gps2m(float lat_a, float lng_a, float lat_b, float lng_b) {
float pk = (float) (180/3.14169);
float a1 = lat_a / pk;
float a2 = lng_a / pk;
float b1 = lat_b / pk;
float b2 = lng_b / pk;
float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2);
float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2);
@mstefanko
mstefanko / gist:890443
Created March 28, 2011 13:27
Get your mobile number
private String getMyNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}