Wednesday, July 21, 2010

How to Connect Face Book in Android ?

http://code.google.com/p/fbconnect-android/source/browse/sample/src/com/codecarpet/fbconnect/sample/MainActivity.java


http://www.mobisoftinfotech.com/blog/android/845/


These links are useful to connect facebook in android.

Monday, July 19, 2010

Android – Listen for incoming SMS messages

public class SMSApp extends IntentReceiver {
private static final String LOG_TAG = "SMSApp";

/* package */ static final String ACTION =
"android.provider.Telephony.SMS_RECEIVED";

public void onReceiveIntent(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
StringBuilder buf = new StringBuilder();
Bundle bundle = intent.getExtras();

if (bundle != null) {
SmsMessage[] messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
for (int i = 0; i < messages.length; i++) {
SmsMessage message = messages[i];
buf.append("Received SMS from ");
buf.append(message.getDisplayOriginatingAddress());
buf.append(" - ");
buf.append(message.getDisplayMessageBody());
}
}
Log.i(LOG_TAG, "[SMSApp] onReceiveIntent: " + buf);
NotificationManager nm = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);

nm.notifyWithText(123, buf.toString(),
NotificationManager.LENGTH_LONG, null);

}
}

private void appendData(StringBuilder buf, String key, String value) {
buf.append(", ");
buf.append(key);
buf.append('=');
buf.append(value);
}
}

SMS notifications in Android

SMSNotify.java
================

public class SMSNotify extends Activity {

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(R.string.app_name); // cancel notification
}
}
================================================
public class SMSNotifyExample extends IntentReceiver {
/** TAG used for Debug-Logging */
private static final String LOG_TAG = “SMSReceiver”;
// public static final int LENGTH_LONG = 10;
/* A Random IDs used for the Notification */
public static final int NOTIFICATION_ID_RECEIVED = 0×1221;

/** The Action fired by the Android-System when a SMS was received.
* We are using the Default Package-Visibility */
static final String ACTION = “android.provider.Telephony.SMS_RECEIVED”;
private CharSequence from = null;
private CharSequence tickerMessage = null;
public void onReceiveIntent(Context context, Intent intent) {

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (intent.getAction().equals(ACTION)) {
// if(message starts with SMStretcher recognize BYTE)
StringBuilder sb = new StringBuilder();

Bundle bundle = intent.getExtras();
if (bundle != null) {
/* Get all messages contained in the Intent*/
SmsMessage[] messages =
Telephony.Sms.Intents.getMessagesFromIntent(intent);

/* Feed the StringBuilder with all Messages found. */
for (SmsMessage currentMessage : messages){
sb.append(“Received compressed SMS\nFrom: “);
/* Sender-Number */
sb.append(currentMessage.getDisplayOriginatingAddress());
// set
from = currentMessage.getDisplayOriginatingAddress();
sb.append(“\n—-Message—-\n”);
/* Actual Message-Content */
sb.append(currentMessage.getDisplayMessageBody());
}
}
/* Logger Debug-Output */
Log.i(LOG_TAG, “[SMSApp] onReceiveIntent: ” + sb);

this.abortBroadcast();
/* Start the Main-Activity */
Intent i = new Intent(context, SMSNotifyActivity.class);
i.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
context.startActivity(i);

// CharSequence from = currentMessage.getDisplayOriginatingAddress();
CharSequence appName = “SMSNotifyExample”;
tickerMessage = sb.toString();
Long theWhen = System.currentTimeMillis();

Intent appIntent = new Intent(Intent.VIEW_ACTION, Sms.Inbox.CONTENT_URI);

Notification notif = new Notification(
context, // our context
R.drawable.incoming, // the icon for the status bar
tickerMessage, // the text to display in the ticker
theWhen, // the timestamp for the notification
from, // the title for the notification
tickerMessage, // the details to display in the notification
i, // the contentIntent (see above)
R.drawable.chat, // the app icon
appName, // the name of the app
appIntent); // intent that shows the inbox when you click on icon

notif.vibrate = new long[] { 100, 250, 100, 500};

nm.notify(R.string.alert_message, notif);

}
}
}
AndroidManifest.xml
=====================




How do you format date and time in Android?

Date date = new Date(location.getTime());
DateFormat dateFormat = DateFormat.getDateTimeInstance();
mTimeText.setText("Time: " + dateFormat.format(date));

How to get date, month, year values from the current date JAVA ?

import java.util.Calendar;

public class CalendarExample
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int dow = cal.get(Calendar.DAY_OF_WEEK);
int dom = cal.get(Calendar.DAY_OF_MONTH);
int doy = cal.get(Calendar.DAY_OF_YEAR);
}
}

Tuesday, July 13, 2010

Important Links

Video ---> http://davanum.wordpress.com/2009/12/04/android-%E2%80%93-videomusic-player-sample-take-2/

Call Telephony Manager ----http://www.google.com/codesearch/p?hl=en#zvQ8rp58BUs/trunk/phone/src/i4nc4mp/myLock/phone/CallPrompt.java&q=itelephony package:http://mylockforandroid\.googlecode\.com&d=0


http://code.google.com/p/teddsdroidtools/source/browse/#svn/trunk/teddsdroidtools/src/tss/droidtools/phone

Android Widget Example Links

http://www.helloandroid.com/tutorials/days-xmas-widget-tutorial

Wednesday, July 7, 2010

How to fetch Contacts List name and number in android?

//=================main.java=========================

private static final int PICK_CONTACT_REQUEST = 1;

private final ContactAccessor mContactAccessor = ContactAccessor
.getInstance();
Boolean select;

// any click event
public void onClick(View v) {
select = true;
pickContact();
}

protected void pickContact() {
startActivityForResult(mContactAccessor.getPickContactIntent(),
PICK_CONTACT_REQUEST);

}


private void loadContactInfo(Uri contactUri) {

AsyncTask task = new AsyncTask() {

@Override
protected ContactInfo doInBackground(Uri... uris) {
return mContactAccessor.loadContact(getContentResolver(),
uris[0]);
}

@Override
protected void onPostExecute(ContactInfo result) {
bindView(result);
}
};

task.execute(contactUri);
}

protected void bindView(ContactInfo contactInfo) {
if (select == true)
{
EditText Name = (EditText) findViewById(R.id.EditText01);
Name.setText(contactInfo.getDisplayName());

EditText Number = (EditText) findViewById(R.id.EditText02);
Number.setText(contactInfo.getPhoneNumber());
}

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_CONTACT_REQUEST && resultCode == RESULT_OK) {
loadContactInfo(data.getData());
}
}


//=====================ContactAccessor.java===============
public abstract class ContactAccessor {

private static ContactAccessor sInstance;

public static ContactAccessor getInstance() {
if (sInstance == null) {
String className;

int sdkVersion = Integer.parseInt(Build.VERSION.SDK); // Cupcake
// style

if (sdkVersion < Build.VERSION_CODES.ECLAIR) { className = "android.contacts.ContactAccessorSdk3_4"; } else { className = "android.contacts.ContactAccessorSdk5"; } try { Class clazz = Class.forName(
className).asSubclass(ContactAccessor.class);
sInstance = clazz.newInstance();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}

return sInstance;
}

public abstract Intent getPickContactIntent();

public abstract ContactInfo loadContact(ContentResolver contentResolver,
Uri contactUri);
}

//=======================ContactAccessorSdk3_4.java==================
public class ContactAccessorSdk3_4 extends ContactAccessor {

/**
* Returns a Pick Contact intent using the pre-Eclair "people" URI.
*/
@Override
public Intent getPickContactIntent() {
return new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
}

/**
* Retrieves the contact information.
*/
@Override
public ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri) {
ContactInfo contactInfo = new ContactInfo();
Cursor cursor = contentResolver.query(contactUri,
new String[]{People.DISPLAY_NAME}, null, null, null);
try {
if (cursor.moveToFirst()) {
contactInfo.setDisplayName(cursor.getString(0));
}
} finally {
cursor.close();
}

Uri phoneUri = Uri.withAppendedPath(contactUri, Phones.CONTENT_DIRECTORY);
cursor = contentResolver.query(phoneUri,
new String[]{Phones.NUMBER}, null, null, Phones.ISPRIMARY + " DESC");

try {
if (cursor.moveToFirst()) {
contactInfo.setPhoneNumber(cursor.getString(0));
}
} finally {
cursor.close();
}

return contactInfo;
}
}

//========================ContactAccessorSdk5.java==============================
public class ContactAccessorSdk5 extends ContactAccessor {

/**
* Returns a Pick Contact intent using the Eclair "contacts" URI.
*/
@Override
public Intent getPickContactIntent() {
return new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
}

/**
* Retrieves the contact information.
*/
@Override
public ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri) {
ContactInfo contactInfo = new ContactInfo();
long contactId = -1;

// Load the display name for the specified person
Cursor cursor = contentResolver.query(contactUri,
new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
try {
if (cursor.moveToFirst()) {
contactId = cursor.getLong(0);
contactInfo.setDisplayName(cursor.getString(1));
}
} finally {
cursor.close();
}

// Load the phone number (if any).
cursor = contentResolver.query(Phone.CONTENT_URI,
new String[]{Phone.NUMBER},
Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");
try {
if (cursor.moveToFirst()) {
contactInfo.setPhoneNumber(cursor.getString(0));
}
} finally {
cursor.close();
}

return contactInfo;
}
}
//======================ContactInfo.java===============================
public class ContactInfo {

private String mDisplayName;
private String mPhoneNumber;

public void setDisplayName(String displayName) {
this.mDisplayName = displayName;
}

public String getDisplayName() {
return mDisplayName;
}

public void setPhoneNumber(String phoneNumber) {
this.mPhoneNumber = phoneNumber;
}

public String getPhoneNumber() {
return mPhoneNumber;
}
}

Friday, July 2, 2010

Using Process Dialog Box in Android

rogressDialog dialog;
dialog = ProgressDialog.show(classname.this, "","Downloading ............", true);
dialog.dismiss();

Android + Google Checkout = Just as good as cash?

Android + Google Checkout = Just as good as cash?: "

As the world inches closer to switching from a cash society to an all-digital payment society, companies are finding new ways to let users exchange money. PayPal bumps transactions between iPhones, Square can process credit card transactions on a Nexus One, and now Google is offering Google Checkout support between Android and Chrome.

The Android Payment Extension is designed to help merchants accept debit and credit card purchases when someone doesn’t have cash available. Street vendors, weekend garage sale folks, or just two people in a coffee house looking to perform a transaction can now use Google Checkout and some QR codes to accomplish the task. Here’s how Google describes the process:

1. Create a Google Checkout merchant account and configure your tax on the Settings Tab

2. Use the Google Checkout Store Gadget Wizard to generate a webstore template

3. Fill in the Google Spreadsheet with information about the items you wish to sell

4. Create a Google Sites page and follow the wizard to embed the Store Gadget

5. Install the Android Payment Chrome Extension

Afterwards, the customer scans a QR code, logs into his/her Checkout account, and completes the transaction. It’s not the most elegant or quickest way to do business, but it’s another option when you’re in a pinch.

Now all Google needs to do is get more people using Google Checkout.


"

Magento webshop on android


Magento is an eCommerce platform, and they are working on releasing their mCommerce platform for Android/iPhone/iPad this august.

Check Internet Connection Android

private boolean CheckInternet() {
ConnectivityManager connec = (ConnectivityManager) getSystemService(getApplicationContext().CONNECTIVITY_SERVICE);
if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED
|| connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) {
return true;
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("No Internet Connectivity ! ").setCancelable(
false).setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
return false;
}
}