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:org.openlmis.core.view.activity.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!isTaskRoot() && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
            && Intent.ACTION_MAIN.equals(getIntent().getAction())) {
        finish();//from  w w  w . j  ava  2  s .  co  m
        return;
    }

    initUI();

    restoreFromResync();
}

From source file:com.esminis.server.library.service.server.ServerNotification.java

public void show(Context context, CharSequence title, CharSequence titlePublic) {
    if (!preferences.contains(context, Preferences.SHOW_NOTIFICATION_SERVER)
            || !preferences.getBoolean(context, Preferences.SHOW_NOTIFICATION_SERVER)) {
        hide(context);//  w ww .  j  a  v a2  s .  co  m
        return;
    }
    if (!serviceIsRunning) {
        serviceIsRunning = true;
        context.startService(new Intent(context, ServerNotificationService.class));
    }
    if (notification == null) {
        Builder builder = setupNotificationBuilder(context, title)
                .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                .setPublicVersion(setupNotificationBuilder(context, titlePublic).build());
        Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        builder.setContentIntent(
                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        notification = builder.build();
    }
    getManager(context).notify(NOTIFICATION_ID, notification);
}

From source file:io.selendroid.ServerInstrumentation.java

public void startActivity(Class activity) {
    if (activity == null) {
        SelendroidLogger.log("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;//from  ww w . ja va  2  s.c o m
    }
    finishAllActivities();
    // start now the new activity
    Intent intent = new Intent(getTargetContext(), activity);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    Activity a = startActivitySync(intent);
}

From source file:com.google.android.gms.nearby.messages.samples.nearbybackgroundbeacons.BackgroundSubscribeIntentService.java

private void updateNotification() {
    List<String> messages = Utils.getCachedMessages(getApplicationContext());
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
    launchIntent.setAction(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    String contentTitle = getContentTitle(messages);
    String contentText = getContentText(messages);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.star_on).setContentTitle(contentTitle).setContentText(contentText)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).setOngoing(true)
            .setContentIntent(pi);//from w w w . j a v  a  2s  .c o  m
    notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.google.codelab.smartlock.MainActivity.java

/**
 * Set the appropriate fragment given the state of the Activity and the Intent used to start it.
 * If the intent is a launcher intent the Splash Fragment is shown otherwise the SignIn Fragment is shown.
 *
 * @param intent Intent used to determine which Fragment is used.
 *///from w  w  w .j  av a 2 s . c o  m
private void setFragment(Intent intent) {
    Fragment fragment;
    String tag;
    if (intent != null && intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
        fragment = new SplashFragment();
        tag = SPLASH_TAG;
    } else {
        fragment = new SignInFragment();
        tag = SIGN_IN_TAG;
    }
    String currentTag = getCurrentFragmentTag();
    if (currentTag == null || !currentTag.equals(tag)) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, tag).commit();
    }
}

From source file:cordova.BackgroundSubscribeIntentService.java

private void updateNotification() {
        List<String> messages = Utils.getCachedMessages(getApplicationContext());
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
        launchIntent.setAction(Intent.ACTION_MAIN);
        launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        String contentTitle = getContentTitle(messages);
        String contentText = getContentText(messages);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(android.R.drawable.star_on).setContentTitle(contentTitle).setContentText(contentText)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).setOngoing(true)
                .setContentIntent(pi);/*from  w ww. ja  v  a2  s. c o  m*/
        notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
    }

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {//from   w w  w. j av a  2 s  .  c  om
        String packageName = obj.getString(PACKAGE_NAME);
        String feedName = obj.getString("sharedFeedName");
        JSONArray ids = obj.getJSONArray(PARTICIPANTS);
        Intent launch = new Intent();
        launch.setAction(Intent.ACTION_MAIN);
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        launch.putExtra("type", "invite_app_feed");
        launch.putExtra("creator", false);
        launch.putExtra("sender", from.id);
        launch.putExtra("sharedFeedName", feedName);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        long[] idArray = new long[ids.length()];
        for (int i = 0; i < ids.length(); i++) {
            idArray[i] = ids.getLong(i);
        }
        launch.putExtra("participants", idArray);
        launch.setPackage(packageName);
        final PackageManager mgr = context.getPackageManager();
        List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
        if (resolved.size() == 0) {
            Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show();
            return;
        }
        ActivityInfo info = resolved.get(0).activityInfo;
        launch.setComponent(new ComponentName(info.packageName, info.name));
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name,
                "Invitation received from " + from.name, "Click to launch application: " + packageName,
                contentIntent);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.kectech.android.wyslink.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from www  .j  a v a 2s  . c  o  m*/
 */
private void sendNotification(String message) {
    //        Intent intent = new Intent(this, MainActivity.class);
    //        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    // http://stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification
    // use the same intent filters as android uses when launches the app
    final Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    // http://stackoverflow.com/questions/25030710/gcm-push-notification-large-icon-size
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification_large);
    float multiplier = getImageFactor(getResources());
    largeIcon = Bitmap.createScaledBitmap(largeIcon, (int) (largeIcon.getWidth() * multiplier),
            (int) (largeIcon.getHeight() * multiplier), false);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_stat_communication_message)
            .setContentTitle("wysLink Message").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PRIVATE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // support from API 17 and above (Android 4.2)
        notificationBuilder.setSubText("click to open");
    }
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Another issue i had in android lollipop is that the small icon was displayed next to the large icon.
    // http://stackoverflow.com/questions/16170648/android-notification-builder-show-a-notification-without-icon/33943309#33943309
    Notification notification = notificationBuilder.build();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int smallIconViewId = this.getResources().getIdentifier("right_icon", "id",
                android.R.class.getPackage().getName());

        if (smallIconViewId != 0) {
            if (notification.contentIntent != null)
                notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notification.headsUpContentView != null)
                notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notification.bigContentView != null)
                notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
        }
    }

    notificationManager.notify(0 /* ID of notification */, notification);
}

From source file:com.dm.material.dashboard.candybar.tasks.IconRequestTask.java

@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {/*  w  w  w .j  av  a 2  s. co m*/
            Thread.sleep(1);
            if (mContext.get().getResources().getBoolean(R.bool.enable_icon_request)
                    || mContext.get().getResources().getBoolean(R.bool.enable_premium_request)) {
                List<Request> requests = new ArrayList<>();
                HashMap<String, String> appFilter = RequestHelper.getAppFilter(mContext.get(),
                        RequestHelper.Key.ACTIVITY);
                if (appFilter.size() == 0) {
                    mError = Extras.Error.APPFILTER_NULL;
                    return false;
                }

                PackageManager packageManager = mContext.get().getPackageManager();

                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent,
                        PackageManager.GET_RESOLVED_FILTER);
                if (installedApps == null || installedApps.size() == 0) {
                    mError = Extras.Error.INSTALLED_APPS_NULL;
                    return false;
                }

                CandyBarMainActivity.sInstalledAppsCount = installedApps.size();

                try {
                    Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager));
                } catch (Exception ignored) {
                }

                for (ResolveInfo app : installedApps) {
                    String packageName = app.activityInfo.packageName;
                    String activity = packageName + "/" + app.activityInfo.name;

                    String value = appFilter.get(activity);

                    if (value == null) {
                        String name = LocaleHelper.getOtherAppLocaleName(mContext.get(), new Locale("en"),
                                packageName);
                        if (name == null) {
                            name = app.activityInfo.loadLabel(packageManager).toString();
                        }

                        boolean requested = Database.get(mContext.get()).isRequested(activity);
                        Request request = Request.Builder().name(name).packageName(app.activityInfo.packageName)
                                .activity(activity).requested(requested).build();

                        requests.add(request);
                    }
                }

                CandyBarMainActivity.sMissedApps = requests;
            }
            return true;
        } catch (Exception e) {
            CandyBarMainActivity.sMissedApps = null;
            mError = Extras.Error.DATABASE_ERROR;
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}

From source file:com.fitc.dooropener.lib.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param status GCM message received.// w w w.  j  a  v a2  s  .c o m
 */
private void sendNotification(GcmDataPayload status) {

    /**
     * This code should find launcher activity of app using this librbary and set it as the what gets launched
     */
    Intent intent = null;
    final PackageManager packageManager = getPackageManager();
    Log.i(TAG, "PACKAGE NAME " + getPackageName());

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

    List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);

    for (final ResolveInfo resolveInfo : appList) {
        if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen)
        {
            intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
            break;
        }
    }
    PendingIntent pendingIntent = null;
    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(getResources().getString(R.string.notif_content_title))
            .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri);

    if (pendingIntent != null) {
        notificationBuilder.setContentIntent(pendingIntent);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}