Skip to content

Instantly share code, notes, and snippets.

@mustafasevgi
Created January 29, 2015 13:41
Show Gist options
  • Save mustafasevgi/fd021ae54331ac1d6188 to your computer and use it in GitHub Desktop.
Save mustafasevgi/fd021ae54331ac1d6188 to your computer and use it in GitHub Desktop.
Add event Calendar, send SMS, installed package, send message with FB Messenger, send Email
private void addCalendar() {
Uri eventsUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {
eventsUri = Uri.parse("content://calendar/events");
}
else {
eventsUri = Uri.parse("content://com.android.calendar/events");
}
Calendar cal = Calendar.getInstance();
ContentValues event = new ContentValues();
event.put(CalendarContract.Events.CALENDAR_ID, 1);
event.put(CalendarContract.Events.TITLE, "Event Titleeeeeeeee");
event.put(CalendarContract.Events.DESCRIPTION, "Event Desceeeeeeeeeeeeee");
event.put(CalendarContract.Events.EVENT_LOCATION, "Event Locationeeeeeeeeeeeeeeeeeee");
event.put(CalendarContract.Events.DTSTART, cal.getTimeInMillis());
event.put(CalendarContract.Events.RRULE, "FREQ=WEEKLY;WKST=SU;BYDAY=WE"); // ileriki zamanlarda tekrarlansin ayarlari
event.put(CalendarContract.Events.ALL_DAY, 1); // 0 for false, 1 for true
event.put(CalendarContract.Events.STATUS, 1);// 0 tentative 1 confirm 2 cancel
event.put(CalendarContract.Events.HAS_ALARM, 1); // 0 for false, 1 for true
event.put(CalendarContract.Events.DURATION, "P3600S");
event.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
// event.put(CalendarContract.Events.DTEND,1433131200000L);
Uri url = getContentResolver().insert(eventsUri, event);
if (url != null) {
Toast.makeText(this, "event kaydedildi", Toast.LENGTH_SHORT).show();
}
}
private void sendSMS() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); // Need to change the build to API 19
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "sms text");
if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else // For early versions, do what worked for you before.
{
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
sendIntent.putExtra("sms_body", "sms text");
startActivity(sendIntent);
}
}
private void sendMail() {
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "your subject");
intentEmail.putExtra(Intent.EXTRA_TEXT, "message body");
intentEmail.setType("message/rfc822");
startActivity(Intent.createChooser(intentEmail, "Choose an email provider :"));
}
private boolean isPackageInstalled(String packagename) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
private void sendMessageWithFBMessenger() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "<---YOUR TEXT HERE--->.");
sendIntent.setType("text/plain");
sendIntent.setPackage(fbMessengerPAckageName);
try {
startActivity(sendIntent);
}
catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(this,"Please Install Facebook Messenger",Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment