Example usage for android.content Intent CATEGORY_LAUNCHER

List of usage examples for android.content Intent CATEGORY_LAUNCHER

Introduction

In this page you can find the example usage for android.content Intent CATEGORY_LAUNCHER.

Prototype

String CATEGORY_LAUNCHER

To view the source code for android.content Intent CATEGORY_LAUNCHER.

Click Source Link

Document

Should be displayed in the top-level launcher.

Usage

From source file:com.android.launcher4.InstallShortcutReceiver.java

private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) {
    if (launchIntent.getAction() == null) {
        launchIntent.setAction(Intent.ACTION_VIEW);
    } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null
            && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    }/*from   w  w w.j av  a2s  .co  m*/
    LauncherAppState app = LauncherAppState.getInstance();
    ShortcutInfo info = app.getModel().infoFromShortcutIntent(context, data, null);
    info.title = ensureValidName(context, launchIntent, info.title);
    return info;
}

From source file:net.ustyugov.jtalk.Notify.java

public static void fileProgress(String filename, Status status) {
    JTalkService service = JTalkService.getInstance();

    Intent i = new Intent(service, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);/*w ww  .  j  av  a 2s . c  o m*/
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(service, 0, i, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service);
    mBuilder.setContentTitle(filename);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setOngoing(false);

    if (status == Status.complete) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done);
        mBuilder.setTicker(service.getString(R.string.Completed));
        mBuilder.setContentText(service.getString(R.string.Completed));
        mBuilder.setAutoCancel(true);
    } else if (status == Status.cancelled) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning);
        mBuilder.setTicker(service.getString(R.string.Canceled));
        mBuilder.setContentText(service.getString(R.string.Canceled));
        mBuilder.setAutoCancel(true);
    } else if (status == Status.refused) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning);
        mBuilder.setTicker(service.getString(R.string.Canceled));
        mBuilder.setContentText(service.getString(R.string.Canceled));
        mBuilder.setAutoCancel(true);
    } else if (status == Status.negotiating_transfer) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done);
        mBuilder.setTicker(service.getString(R.string.Waiting));
        mBuilder.setContentText(service.getString(R.string.Waiting));
    } else if (status == Status.in_progress) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
        mBuilder.setTicker(service.getString(R.string.Downloading));
        mBuilder.setContentText(service.getString(R.string.Downloading));
    } else if (status == Status.error) {
        mBuilder.setSmallIcon(android.R.drawable.stat_sys_warning);
        mBuilder.setTicker(service.getString(R.string.Error));
        mBuilder.setContentText(service.getString(R.string.Error));
        mBuilder.setAutoCancel(true);
    } else {
        return;
    }

    NotificationManager mng = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(NOTIFICATION_FILE, mBuilder.build());
}

From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java

private void buildNotification(NotificationCompat.Action action, boolean updateLargeIcon) {

    CustomTrack playSong = getCurrentTrack();

    if (playSong == null)
        return;//from   ww w  . j  a  v a2  s.  com

    NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
    style.setShowActionsInCompactView(0, 1, 2);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // open last activity when tapping notification
    Intent openAppIntent = new Intent(this, MainArtistsListActivity.class);
    openAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    openAppIntent.setAction(Intent.ACTION_MAIN);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, openAppIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    builder.setSmallIcon(android.R.drawable.ic_media_play).setLargeIcon(mLargeIconBitmap)
            .setContentTitle(playSong.getTrackName()).setContentText(playSong.getArtistsNamesList())
            .setStyle(style).setShowWhen(false) // hide time in notification
            .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS))
            .addAction(action).addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT));

    if (updateLargeIcon) {

        Picasso.Builder picassoBuilder = new Picasso.Builder(this);
        Picasso picasso = picassoBuilder.build();
        // to avoid too many requests when user jumps on different tracks too fast, cancel latest one.
        picasso.cancelRequest(mTarget);

        mTarget = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                mLargeIconBitmap = bitmap;
                builder.setLargeIcon(mLargeIconBitmap);

                mNotification = builder.build();

                if (mShowNotification) {
                    showCancelNotification(true);
                }
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }
        };

        String url = playSong.getCustomImageBig().getUrl();

        if (url != null) {
            picasso.load(url).into(mTarget);
        }
    }

    mNotification = builder.build();
    if (mShowNotification) {
        showCancelNotification(true);
    }
}

From source file:com.kentli.cycletrack.RecordingActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(/*from   w  w w  .  jav a2s . co m*/
            "Your phone's GPS is disabled. CycleTracks needs GPS to determine your location.\n\nGo to System Settings now to enable GPS?")
            .setCancelable(false).setPositiveButton("GPS Settings...", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    final ComponentName toLaunch = new ComponentName("com.android.settings",
                            "com.android.settings.SecuritySettings");
                    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setComponent(toLaunch);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivityForResult(intent, 0);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.brewcrewfoo.performance.activities.PCSettings.java

public static boolean isDownloadManagerAvailable(Context context) {
    try {//from   ww w  . j  a  va2  s .  c  o m
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClassName("com.android.providers.downloads.ui",
                "com.android.providers.downloads.ui.DownloadList");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.samsung.multiwindow.MultiWindow.java

/**
 * Get the MultiWindow enabled applications and activity names
 * //from w ww  .  ja  v a2 s.  co m
 * @param windowType
 *            The window type freestyle or splitstyle.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * 
 */
private void getMultiWindowApps(final String windowType, final CallbackContext callbackContext)
        throws JSONException {

    if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
        Log.d(TAG, "Inside getMultiWindowApps");
    }
    cordova.getThreadPool().execute(new Runnable() {

        public void run() {

            JSONArray multiWindowApps = new JSONArray();
            Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
            List<ResolveInfo> resolveInfos = cordova.getActivity().getPackageManager().queryIntentActivities(
                    intent, PackageManager.GET_RESOLVED_FILTER | PackageManager.GET_META_DATA);

            try {
                // Get the multiwindow enabled applications

                int index = 0;
                for (ResolveInfo r : resolveInfos) {
                    if (r.activityInfo != null && r.activityInfo.applicationInfo.metaData != null) {
                        if (r.activityInfo.applicationInfo.metaData
                                .getBoolean("com.sec.android.support.multiwindow")
                                || r.activityInfo.applicationInfo.metaData
                                        .getBoolean("com.samsung.android.sdk.multiwindow.enable")) {
                            JSONObject appInfo = new JSONObject();
                            boolean bUnSupportedMultiWinodw = false;
                            if (windowType.equalsIgnoreCase("splitstyle")) {
                                if (r.activityInfo.metaData != null) {
                                    String activityWindowStyle = r.activityInfo.metaData
                                            .getString("com.sec.android.multiwindow.activity.STYLE");
                                    if (activityWindowStyle != null) {
                                        ArrayList<String> activityWindowStyles = new ArrayList<String>(
                                                Arrays.asList(activityWindowStyle.split("\\|")));
                                        if (!activityWindowStyles.isEmpty()) {
                                            if (activityWindowStyles.contains("fullscreenOnly")) {
                                                bUnSupportedMultiWinodw = true;
                                            }
                                        }
                                    }
                                }
                            }

                            if (!bUnSupportedMultiWinodw || !windowType.equalsIgnoreCase("splitstyle")) {
                                appInfo.put("packageName", r.activityInfo.applicationInfo.packageName);
                                appInfo.put("activity", r.activityInfo.name);
                                multiWindowApps.put(index++, appInfo);
                            }
                        }
                    }
                }
                callbackContext.success(multiWindowApps);
            } catch (Exception e) {

                callbackContext.error(e.getMessage());
            }

        }
    });
}

From source file:org.mariotaku.twidere.provider.TweetStoreProvider.java

private void onNewItemsInserted(final Uri uri, final int count, final ContentValues... values) {
    if (uri == null || values == null || values.length == 0 || count == 0)
        return;//w  w  w  .  j av  a  2  s.c  o  m
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    switch (getTableId(uri)) {
    case URI_STATUSES: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false))
            return;
        final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount);
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME);
        content_intent.putExtras(content_extras);
        builder.setOnlyAlertOnce(true);
        final Notification notification = buildNotification(builder, res.getString(R.string.new_notifications),
                message, message, R.drawable.ic_stat_tweet, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, notification);
        break;
    }
    case URI_MENTIONS: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false))
            return;
        if (mNewMentionsCount > 1) {
            builder.setNumber(mNewMentionsCount);
        }
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        ContentValues notification_value = null;
        int notified_count = 0;
        for (final ContentValues value : values) {
            final String screen_name = value.getAsString(Statuses.SCREEN_NAME);
            if (!isFiltered(mDatabase, screen_name, value.getAsString(Statuses.SOURCE),
                    value.getAsString(Statuses.TEXT_PLAIN))) {
                if (notification_value == null) {
                    notification_value = value;
                }
                screen_names.add(screen_name);
                notified_count++;
            }
        }
        if (notified_count == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_STATUS);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID,
                    notification_value.getAsString(Statuses.ACCOUNT_ID));
            uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID,
                    notification_value.getAsString(Statuses.STATUS_ID));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());

        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS);
            content_intent.putExtras(content_extras);
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_mention_multiple,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_mention,
                    display_screen_name ? notification_value.getAsString(Statuses.SCREEN_NAME)
                            : notification_value.getAsString(Statuses.NAME));
        }
        final String message = notification_value.getAsString(Statuses.TEXT_PLAIN);
        final String profile_image_url_string = notification_value.getAsString(Statuses.PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_mention, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, notification);
        break;
    }
    case URI_DIRECT_MESSAGES_INBOX: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false))
            return;
        if (mNewMessagesCount > 1) {
            builder.setNumber(mNewMessagesCount);
        }
        final List<String> screen_names = new NoDuplicatesArrayList<String>();
        final ContentValues notification_value = values[0];
        for (final ContentValues value : values) {
            screen_names.add(value.getAsString(DirectMessages.SENDER_SCREEN_NAME));
        }
        if (notification_value == null)
            return;
        final String title;
        if (screen_names.size() > 1) {
            title = res.getString(R.string.notification_direct_message_multiple,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME),
                    screen_names.size() - 1);
        } else {
            title = res.getString(R.string.notification_direct_message,
                    display_screen_name ? notification_value.getAsString(DirectMessages.SENDER_SCREEN_NAME)
                            : notification_value.getAsString(DirectMessages.SENDER_NAME));
        }
        final String message = notification_value.getAsString(DirectMessages.TEXT_PLAIN);
        final String profile_image_url_string = notification_value
                .getAsString(DirectMessages.SENDER_PROFILE_IMAGE_URL);
        final File profile_image_file = mProfileImageLoader.getCachedImageFile(
                display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                        : profile_image_url_string);
        final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
        builder.setLargeIcon(Bitmap.createScaledBitmap(profile_image_file != null && profile_image_file.isFile()
                ? BitmapFactory.decodeFile(profile_image_file.getPath())
                : BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default), w, h, true));
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent;
        if (values.length == 1) {
            final Uri.Builder uri_builder = new Uri.Builder();
            final long account_id = notification_value.getAsLong(DirectMessages.ACCOUNT_ID);
            final long conversation_id = notification_value.getAsLong(DirectMessages.SENDER_ID);
            uri_builder.scheme(SCHEME_TWIDERE);
            uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
            uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id));
            uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id));
            content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
        } else {
            content_intent = new Intent(context, HomeActivity.class);
            content_intent.setAction(Intent.ACTION_MAIN);
            content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final Bundle content_extras = new Bundle();
            content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES);
            content_intent.putExtras(content_extras);
        }
        final Notification notification = buildNotification(builder, title, title, message,
                R.drawable.ic_stat_direct_message, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, notification);
        break;
    }
    }
}

From source file:com.jungle.base.utils.MiscUtils.java

public static String getMainLauncherActivity() {
    try {/*from www  .jav a2s.c  om*/
        Context context = BaseApplication.getAppContext();
        PackageManager manager = context.getPackageManager();
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
        Collections.sort(list, new ResolveInfo.DisplayNameComparator(manager));

        String packageName = MiscUtils.getPackageName();
        for (ResolveInfo info : list) {
            if (TextUtils.equals(packageName, info.activityInfo.packageName)) {
                return info.activityInfo.name;
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.pdmanager.views.patient.MainActivity.java

@Override
public void onMessageReceived(final CNMessage cnMessage) {
    if (application.getUniqueId().equals(cnMessage.getUniqueId())) {
        return;/*from  w w w .  j  av a 2s  .co m*/
    }

    if (cnMessage.getMessageType() == CNMessage.CNMessageType.Calling) {

        if (application.isInConference()) {
            application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.Busy, null);
            return;
        }

        callDialog = new AlertDialog.Builder(this).create();
        LayoutInflater inflater = getLayoutInflater();
        View incomingCallDialog = inflater.inflate(R.layout.incoming_call_dialog, null);
        incomingCallDialog.setAlpha(0.5f);
        callDialog.setView(incomingCallDialog);

        TextView caller = (TextView) incomingCallDialog.findViewById(R.id.caller);
        caller.setText(cnMessage.getDisplayName());

        Button answerButton = (Button) incomingCallDialog.findViewById(R.id.answer_button);
        answerButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                application.setConferenceId(cnMessage.getConferenceId());
                application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.AnswerAccept, null);
                callDialog.hide();
                currentRingtone.stop();

                Intent intent = new Intent(application.getContext(), MainActivity.class);
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                startActivity(intent);

                application.join(application.getConferenceId(), true);
            }
        });

        Button declineButton = (Button) incomingCallDialog.findViewById(R.id.decline_button);
        declineButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                application.sendCNMessage(cnMessage.getFrom(), CNMessage.CNMessageType.AnswerDecline, null);
                currentRingtone.stop();
                callDialog.hide();
            }
        });

        callDialog.setCancelable(false);
        callDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        //play current Ringtone
        currentRingtone.play();
        callDialog.show();
    } else if (cnMessage.getMessageType() == CNMessage.CNMessageType.Cancel) {
        currentRingtone.stop();
        callDialog.hide();
    } else if (cnMessage.getMessageType() == CNMessage.CNMessageType.EndCall) {
        if (application.leave()) {
            int count = getFragmentManager().getBackStackEntryCount();
            String name = getFragmentManager().getBackStackEntryAt(count - 2).getName();
            getFragmentManager().popBackStack(name, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }
}

From source file:com.example.android.home.Home.java

/**
 * Loads the list of installed applications in mApplications.
 *///  w  ww .j  a  v a 2  s .c  o m
private void loadApplications(boolean isLaunching) {
    if (isLaunching && mApplications != null) {
        return;
    }

    PackageManager manager = getPackageManager();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));

    if (apps != null) {
        final int count = apps.size();

        if (mApplications == null) {
            mApplications = new ArrayList<ApplicationInfo>(count);
        }
        mApplications.clear();

        for (int i = 0; i < count; i++) {
            //for (int i = 0; i < 6; i++) {            // show only 6 apps
            ApplicationInfo application = new ApplicationInfo();
            ResolveInfo info = apps.get(i);

            application.title = info.loadLabel(manager);
            application.setActivity(
                    new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name),
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

            Log.v("Home APP", "package neme= " + info.activityInfo.applicationInfo.packageName);
            Log.v("Home APP", "neme= " + info.activityInfo.name);
            Log.v("Home APP", "title= " + application.title);

            application.icon = info.activityInfo.loadIcon(manager);

            // TODO
            // Replace Icons
            //if((application.title+"").equals("Calculator")) application.icon = getResources().getDrawable(R.drawable.ic_launcher_home_big);

            // Add Application
            if ((application.title + "").equals("Browser"))
                mApplications.add(application);
            if ((application.title + "").equals("Phone"))
                mApplications.add(application);
            if ((application.title + "").equals("People"))
                mApplications.add(application);
            if ((application.title + "").equals("Messaging"))
                mApplications.add(application);
            if ((application.title + "").equals("Settings"))
                mApplications.add(application);

        }

        // Took from http://hi-android.info/src/index.html
        // ********************* ADD Call Log
        ApplicationInfo application = new ApplicationInfo();
        application.title = "Call Log";
        application.icon = getResources().getDrawable(R.drawable.ic_launcher_home);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.RecentCallsListActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);
    }
}