- Press Back button two time to exit and move task to background
1234567891011121314151617181920boolean doubleBackToExitPressedOnce = false;///////@Overridepublic void onBackPressed() {if (doubleBackToExitPressedOnce) {super.onBackPressed();return;}this.doubleBackToExitPressedOnce = true;Toast.makeText(this, "Chạm lần nữa để thoát", Toast.LENGTH_SHORT).show();new Handler().postDelayed(new Runnable() {@Overridepublic void run() {doubleBackToExitPressedOnce = false;}}, 2000); //2000 <-> 2 second} - Open message, put adress and body text on it
12345678private void sendSmS(String address, String sms_body){Intent smsIntent = new Intent(Intent.ACTION_VIEW);smsIntent.setType("vnd.android-dir/mms-sms");smsIntent.putExtra("address", address);smsIntent.putExtra("sms_body",sms_body);startActivity(smsIntent);} - Made a USSD call
123456789101112131415161718192021private void Uri ussdToCallableUri(String ussd) {String uriString = "";if(!ussd.startsWith("tel:"))uriString += "tel:";for(char c : ussd.toCharArray()) {if(c == '#')uriString += Uri.encode("#");elseuriString += c;}return Uri.parse(uriString);}private void callUSSD(String code){Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(code));startActivity(callIntent);}//UsecallUSSD("*101#"); - Good Calendar Date Picker
1https://github.com/code-troopers/android-betterpickers
12345678910111213141516171819202122232425@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);imageButtonCalendar.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {FragmentManager fm = getFragmentManager();DateTime now = DateTime.now();CalendarDatePickerDialogFragment calendarDatePickerDialogFragment = CalendarDatePickerDialogFragment.newInstance(NgayFragment.this, year, month - 1,day);calendarDatePickerDialogFragment.setDateRange(new MonthAdapter.CalendarDay(oldestYear, oldestMonth - 1, oldestDay),new MonthAdapter.CalendarDay(now.getYear(), now.getMonthOfYear() - 1, now.getDayOfMonth()));calendarDatePickerDialogFragment.show(fm, FRAG_TAG_DATE_PICKER);}});;}/////@Overridepublic void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {//your code} - Retrieve contact name from phone number
12345678910111213141516171819public static String getContactName(Context context, String phoneNumber) {ContentResolver cr = context.getContentResolver();Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));Cursor cursor = cr.query(uri, new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);if (cursor == null) {return null;}String contactName = null;if(cursor.moveToFirst()) {contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));}if(cursor != null && !cursor.isClosed()) {cursor.close();}if(contactName == null)return phoneNumber;return contactName;} - Updating….