Monday, October 25, 2010

How to maintance the phone ?

25 Oct 2010
How to change Google Account Password ?
Go to Menu -> Settings -> Applications -> Manage Applications
Click on GMail in the list and, if needed, "Force Stop" then "Clear data"
Click on Google Apps in the list and, if needed, "Force Stop" it, but DO NOT clear data
Click on "Clear Data" on GMail Storage
Back to home and open any Google Application
Re-enter your Google account information.

Friday, October 1, 2010

How to access Services ?

01 Oct 2010
How to cancel Notification ?
int NOTIFICATION_ID= 1234;
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

manager.cancel(NOTIFICATION_ID);

30 Sep 2010
How to show Notication ?

CharSequence title = "Title";
CharSequence text = "Text";
Context c = getApplicationContext();

Intent intent = new Intent(c, Main.class);
PendingIntent intent2 = PendingIntent.getActivity(c, 0, intent, 0);

Notification n = new Notification(R.drawable.icon, text, System.currentTimeMillis());
n.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
n.setLatestEventInfo(c, title, text, intent2);

NotificationManager m = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
m.notify(1, n);

18 Aug 2010
How to open Photos ?
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 0);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
try {
InputStream fileInputStream = getApplicationContext().getContentResolver().openInputStream(selectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

16 Aug 2010
How to dismiss keyboard ?
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

How to access clipboard ?
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText("testing");

How to vibrate ?
Vibrator vv = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);

Wednesday, August 18, 2010

How to do in resources ?

18 Aug 2010
Where to put our own resource files ?

/assets


How to define String array in Resource?

<string-array name="string_array_name">
<item>text_string</item>
</string-array>

Monday, August 16, 2010

How to do in Algorithms ?

16 Aug 2010
How to clac MD5 ?

MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte[] messageDigest = digest.digest();
StringBuffer hexString = new StringBuffer();
for(int i = 0 ; i < messageDigest.length ; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();

How to do in Web related components ?

16 Aug 2010
How to get the bookmarks ?

Cursor cursor = Browser.getAllBookmarks(getContentResolver());
cursor.moveToFirst();
do {
Log.d("Bookmark: ", cursor.getString(1));
} while (cursor.moveToNext());


How to load data in WebView ?

webview.loadData("<html></html>", "text/html", "utf-8");

How to do in XML reader and writer ?

16 Aug 2010
How to make DefaultHandler.startElement() running ?

factory.setNamespaceAware(false);
factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);

How to in Thread ?

16 Aug 2010
How to do a Thread ?

private Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};

new Thread(new Runnable() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
handler.sendEmptyMessage(0);
}
}
}).start();

Sunday, August 15, 2010

How to do in Text ?

16 Aug 2010
How to compare String and Editable ?

Editable.toString().equals(String)

How to configure View in XML ?

16 Aug 2010
How to set the EditView as Password Mask ?
android:password="true"
How to make TextView display center ?
android:gravity="center_vertical|center_horizontal"