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.pquery.Main.java

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

    // We only want single instance of this activity at top
    // If launched via a notification and by normal icon android can try
    //to create another copy of activity down stack
    // Don't want that so pop superfluus activity
    ///*from  w w w . java2 s.  c o m*/
    // http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ
    if (!isTaskRoot()) {
        final Intent intent = getIntent();
        final String intentAction = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null
                && intentAction.equals(Intent.ACTION_MAIN)) {
            Logger.w("Not root. Finishing Main Activity instead of launching");
            finish();
            return;
        }
    }

    // Make Jericho form parsing case sensitive
    Config.CurrentCompatibilityMode = Config.CompatibilityMode.MOZILLA;

    // Enable logging (if pref set)
    // If first time logging has been initialised a new log file will be created
    Logger.setEnable(Prefs.getDebug(this));
    Logger.d("enter");

    // Enable progress bar at top of window
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.main2);

    String title = getIntent().getStringExtra("title");
    if (title != null)
        doDialog = true;
}

From source file:info.balthaus.geologrenewed.app.service.BackgroundService.java

@SuppressLint("NewApi")
@Override/*from   w w w  . jav a  2s  . c om*/
public void onCreate() {
    super.onCreate();
    Debug.log("Service created");

    if (thread == null) {
        Debug.log("Launching thread");
        thread = new ServiceThread();
        thread.setContext(getApplicationContext());
        thread.start();
    }

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock");

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setClass(this, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent = PendingIntent.getActivity(this, 0, i, 0);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service)
            .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setOngoing(true).setContentTitle(getString(R.string.service_title))
            .setContentText(getString(R.string.service_waiting));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        notificationBuilder.setShowWhen(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons
        notificationBuilder.
        setPriority(Notification.PRIORITY_MAX).
        addAction(0, "A", notificationIntent).
        addAction(0, "B", notificationIntent).
        addAction(0, "C", notificationIntent);
        */
    }

    updateNotification();
}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.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 = "Deseja abrir a porta?";

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_digitaldesk_big).setContentTitle(contentTitle)
            .setContentText(contentText).setStyle(new NotificationCompat.BigTextStyle().bigText(contentText))
            .setOngoing(false).setContentIntent(pi);
    notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java

public static void setStatusbar(Activity activity) {
    try {/*from  w  w w . ja  v  a  2 s . c  o m*/
        NotificationManager mNotificationManager = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        // set statusbar
        if (Preferences.APPEARANCE_STATUSBAR) {
            Context context = activity.getApplicationContext();
            Intent intent = new Intent(context, menion.android.whereyougo.gui.activity.MainActivity.class);
            // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setAction(Intent.ACTION_MAIN);
            PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
            final int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
            Notification notif = null;
            if (sdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
                notif = new Notification(R.drawable.ic_title_logo, A.getAppName(), System.currentTimeMillis());
                notif.setLatestEventInfo(activity, A.getAppName(), "", pIntent);
            } else {
                NotificationCompat.Builder builder = new NotificationCompat.Builder(activity)
                        .setContentTitle(A.getAppName()).setSmallIcon(R.drawable.ic_title_logo)
                        .setContentIntent(pIntent);
                notif = builder.build();
            }
            notif.flags = Notification.FLAG_ONGOING_EVENT;
            mNotificationManager.notify(0, notif);
        } else {
            mNotificationManager.cancel(0);
        }
    } catch (Exception e) {
        // Logger.e(TAG, "setStatusbar(" + activity + ")", e);
    }
}

From source file:com.google.vr.sdk.samples.video360.VideoActivity.java

/**
 * Checks that the appropriate permissions have been granted. Otherwise, the sample will wait
 * for the user to grant the permission.
 *
 * @param savedInstanceState unused in this sample but it could be used to track video position
 *//*from w w w  . ja v  a 2 s .c o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_activity);

    // Configure the MonoscopicView which will render the video and UI.
    videoView = (MonoscopicView) findViewById(R.id.video_view);
    VideoUiView videoUi = (VideoUiView) findViewById(R.id.video_ui_view);
    videoUi.setVrIconClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Convert the Intent used to launch the 2D Activity into one that can launch the VR
            // Activity. This flow preserves the extras and data in the Intent.
            DaydreamApi api = DaydreamApi.create(VideoActivity.this);
            if (api != null) {
                // Launch the VR Activity with the proper intent.
                Intent intent = DaydreamApi
                        .createVrIntent(new ComponentName(VideoActivity.this, VrVideoActivity.class));
                intent.setData(getIntent().getData());
                intent.putExtra(MediaLoader.MEDIA_FORMAT_KEY,
                        getIntent().getIntExtra(MediaLoader.MEDIA_FORMAT_KEY, Mesh.MEDIA_MONOSCOPIC));
                api.launchInVr(intent);
                api.close();
            } else {
                // Fall back for devices that don't have Google VR Services. This flow should only
                // be used for older Cardboard devices.
                Intent intent = new Intent(getIntent()).setClass(VideoActivity.this, VrVideoActivity.class);
                intent.removeCategory(Intent.CATEGORY_LAUNCHER);
                intent.setFlags(0); // Clear any flags from the previous intent.
                startActivity(intent);
            }

            // See VrVideoActivity's launch2dActivity() for more info about why this finish() call
            // may be required.
            finish();
        }
    });
    videoView.initialize(videoUi);

    // Boilerplate for checking runtime permissions in Android.
    if (ContextCompat.checkSelfPermission(this,
            permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        View button = findViewById(R.id.permission_button);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCompat.requestPermissions(VideoActivity.this,
                        new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                        READ_EXTERNAL_STORAGE_PERMISSION_ID);
            }
        });
        // The user can click the button to request permission but we will also click on their behalf
        // when the Activity is created.
        button.callOnClick();
    } else {
        // Permission has already been granted.
        initializeActivity();
    }
}

From source file:com.apexlabs.alarm.AlarmService.java

private Intent getClockIntent() {
    PackageManager packageManager = getPackageManager();
    Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);

    // Verify clock implementation
    String clockImpls[][] = {//  w  ww  .j  ava 2s  .co  m
            { "HTC", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
            { "Standard", "com.android.deskclock", "com.android.deskclock.AlarmClock" },
            { "Froyo", "com.google.android.deskclock", "com.android.deskclock.DeskClock" },
            { "Motorola", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock" },
            { "Sony Ericsson", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" }, { "Samsung",
                    "com.sec.android.app.clockpackage", "com.sec.android.app.clockpackage.ClockPackage" } };

    boolean foundClockImpl = false;

    for (int i = 0; i < clockImpls.length; i++) {
        String packageName = clockImpls[i][1];
        String className = clockImpls[i][2];
        try {
            ComponentName cn = new ComponentName(packageName, className);
            packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
            alarmClockIntent.setComponent(cn);
            foundClockImpl = true;
            break;
        } catch (NameNotFoundException e) {
            Log.d(TAG, "Alarm clock " + clockImpls[i][0] + " not found");
        }
    }

    if (foundClockImpl) {
        alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    return alarmClockIntent;
}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherService.java

private void patchFile(Bundle data) {
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resultIntent.setAction(Intent.ACTION_MAIN);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);

    final Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setOngoing(true);//from ww  w.j a v a  2 s.  co  m
    builder.setContentTitle(getString(R.string.overall_progress));
    builder.setContentIntent(pendingIntent);
    builder.setProgress(0, 0, true);

    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(1, builder.build());

    Patcher.ProgressListener listener = new Patcher.ProgressListener() {
        @Override
        public void onProgressUpdated(long bytes, long maxBytes) {
            updateProgress(bytes, maxBytes);
        }

        @Override
        public void onFilesUpdated(long files, long maxFiles) {
            builder.setContentText(String.format(getString(R.string.overall_progress_files), files, maxFiles));
            builder.setProgress((int) maxFiles, (int) files, false);
            nm.notify(1, builder.build());

            updateFiles(files, maxFiles);
        }

        @Override
        public void onDetailsUpdated(String text) {
            updateDetails(text);
        }
    };

    Bundle result = PatcherUtils.patchFile(this, data, listener);

    if (result != null) {
        String newFile = result.getString(PatcherUtils.RESULT_PATCH_FILE_NEW_FILE);
        int errorCode = result.getInt(PatcherUtils.RESULT_PATCH_FILE_ERROR_CODE);
        boolean failed = result.getBoolean(PatcherUtils.RESULT_PATCH_FILE_FAILED);
        onPatchedFile(failed, errorCode, newFile);
    }

    nm.cancel(1);
}

From source file:com.tesfayeabel.lolchat.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_leave:
        finish();//from  w w w.j av  a2 s.  co  m
        stopService(new Intent(this, ChatService.class));
        Intent mainIntent = new Intent(this, LoginActivity.class);
        mainIntent.setAction(Intent.ACTION_MAIN);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        startActivity(mainIntent);
        return true;
    case R.id.action_about:
        Intent aboutActivity = new Intent(this, AboutActivity.class);
        startActivity(aboutActivity);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.launcher.silverfish.LauncherActivity.java

private void autoSortApplications() {

    // Set up both SQL helper and package manager
    LauncherSQLiteHelper sql = new LauncherSQLiteHelper(this.getBaseContext());
    PackageManager mPacMan = getApplicationContext().getPackageManager();

    // Set MAIN and LAUNCHER filters, so we only get activities with that defined on their manifest
    Intent i = new Intent(Intent.ACTION_MAIN, null);
    i.addCategory(Intent.CATEGORY_LAUNCHER);

    // Get all activities that have those filters
    List<ResolveInfo> availableActivities = mPacMan.queryIntentActivities(i, 0);

    // Store here the packages and their categories IDs
    // This will allow us to add all the apps at once instead opening the database over and over
    HashMap<String, Integer> pkg_categoryId = PackagesCategories.setCategories(getApplicationContext(),
            availableActivities);/* w  ww  . j ava 2  s. com*/

    // Then add all the apps to their corresponding tabs at once
    sql.addAppsToTab(pkg_categoryId);
}

From source file:eu.chainfire.geolog.service.BackgroundService.java

@SuppressLint("NewApi")
@Override/*from  w ww . j  a  va 2s. c om*/
public void onCreate() {
    super.onCreate();
    Debug.log("Service created");

    if (thread == null) {
        Debug.log("Launching thread");
        thread = new ServiceThread();
        thread.setContext(getApplicationContext());
        thread.start();
    }

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock");

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setClass(this, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent = PendingIntent.getActivity(this, 0, i, 0);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service)
            .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setOngoing(true).setContentTitle(getString(R.string.service_title))
            .setContentText(getString(R.string.service_waiting));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        notificationBuilder.setShowWhen(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons
        notificationBuilder.
           setPriority(Notification.PRIORITY_MAX).
           addAction(0, "A", notificationIntent).
           addAction(0, "B", notificationIntent).
           addAction(0, "C", notificationIntent);
        */
    }

    updateNotification();
}