Launch calendar event activity. - Android Activity

Android examples for Activity:Activity Start

Description

Launch calendar event activity.

Demo Code


import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Parcelable;
import android.telephony.SmsManager;
import android.text.Html;
import android.util.Log;

public class Main{
    private static final String TAG = ExternalIntentUtils.class
            .getSimpleName();//from w w  w .  java  2  s . co m
    /**
     * Launch calendar event activity.
     * @param context
     * @param beginTime
     * @param endTime
     * @param eventSubject
     * @param description
     * @param eventLocation
     */
    public static void addCalendarEvent(Context context, long beginTime,
            long endTime, String eventSubject, String description,
            String eventLocation) {
        Log.d(TAG, "Add calendar event, beginTime : " + beginTime
                + ", endTime : " + endTime);
        Log.d(TAG, "EventTitle : " + eventSubject + ", description :"
                + description + ", eventLocation : " + eventLocation);
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", beginTime);
        intent.putExtra("endTime", endTime);
        intent.putExtra("title", eventSubject);
        intent.putExtra("eventLocation", eventLocation);
        intent.putExtra("description", description);
        startActivity(context, intent, true);
    }
    /**
     * Launch a new activity with ActivityNotFoundException caught.
     * 
     * @param context
     * @param intent
     * @param toast true if your want to show a message toast when ActivityNotFoundException occurs.
     * @return
     */
    public static boolean startActivity(Context context, Intent intent,
            boolean toast) {
        try {
            context.startActivity(intent);
            return true;
        } catch (android.content.ActivityNotFoundException e) {
            if (toast) {
                toastActivityNotFound(context);
            }
            return false;
        }
    }
    public static void toastActivityNotFound(Context context) {
        String toast = null;
        /*
         * The language codes are two-letter lowercase ISO language codes (such as "en") as defined by
         * <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a>.
         * The country codes are two-letter uppercase ISO country codes (such as "US") as defined by
         * <a href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3">ISO 3166-1</a>.
         * The variant codes are unspecified.
         */
        Locale loc = Locale.getDefault();
        String language = loc.getLanguage();
        String country = loc.getCountry();
        System.out.println("Default locale is " + language + "_" + country);
        if (language.equals("zh")) {
            if (country.equals("TW") || country.equals("HK")) {
                // 
                toast = "traditional Chinese";
            } else {
                // 
                toast = "simplified Chinese";
            }
        } else {
            // non zh, use en.
            toast = "Can't find relative application";
        }
        android.widget.Toast.makeText(context, toast,
                android.widget.Toast.LENGTH_SHORT).show();
    }
}

Related Tutorials