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.nks.nksmod.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*w w  w. java 2 s. c  om*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_info) {
        Intent intent = new Intent(this, InformationActivity.class);
        startActivity(intent);
    }

    if (id == R.id.nav_update) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(ComponentName
                .unflattenFromString("com.nks.nksmod.otaupdater/com.nks.nksmod.otaupdater.OTAUpdaterActivity"));
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    /* if (id == R.id.nav_gallery) {
            
    } else if (id == R.id.nav_slideshow) {
            
    } else if (id == R.id.nav_manage) {
            
    } else if (id == R.id.nav_share) {
            
    } else if (id == R.id.nav_send) {
            
    } */

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java

private void setupSimplePreferencesScreen() {
    addPreferencesFromResource(R.xml.pref_application);

    applicationCategory = (PreferenceCategory) findPreference("header_application");

    // Listen for check/uncheck all tap
    findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override/*from w ww. j a  v a  2s .c  o m*/
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) {
                // Uncheck or check all items
                ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1);
            }
            return true;
        }
    });

    class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> {
        private PackageManager packageManager;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true);
        }

        @Override
        protected List<ApplicationInfo> doInBackground(String... notif) {

            packageManager = getApplicationContext().getPackageManager();

            // Comparator used to sort applications by name
            class CustomComparator implements Comparator<ApplicationInfo> {
                @Override
                public int compare(ApplicationInfo arg0, ApplicationInfo arg1) {
                    return arg0.loadLabel(packageManager).toString()
                            .compareTo(arg1.loadLabel(packageManager).toString());
                }
            }

            // Get installed applications
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            List<ApplicationInfo> appList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            // Sort by application name
            Collections.sort(appList, new CustomComparator());

            return appList;
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            // Add each application to screen
            for (ApplicationInfo appInfo : result) {
                CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this);
                c.setTitle(appInfo.loadLabel(packageManager).toString());
                c.setSummary(appInfo.packageName);
                c.setIcon(appInfo.loadIcon(packageManager));
                c.setKey(appInfo.packageName);
                c.setChecked(true);

                c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference arg0, Object arg1) {
                        // On tap, show an enabled/disabled notification on the desktop
                        Object[] notif = new Object[3];

                        if (arg1.toString().equals("true")) {
                            notif[0] = arg0.getTitle().toString() + " notifications enabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        } else {
                            notif[0] = arg0.getTitle().toString() + " notifications disabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        }

                        new TestTask().execute(notif);

                        return true;
                    }

                });

                applicationCategory.addPreference(c);
            }
            progressDialog.dismiss();
        }
    }

    new ApplicationTask().execute();

}

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

private void autoSortApplications() {

    // Set up both SQL helper and package manager
    LauncherSQLiteHelper sql = new LauncherSQLiteHelper((App) getApplication());
    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, Long> pkg_categoryId = PackagesCategories.setCategories(getApplicationContext(),
            availableActivities);/*from   w  w w .j a va 2 s . c o  m*/

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

From source file:org.frc836.database.DBSyncService.java

@Override
public void onCreate() {
    super.onCreate();
    // loadTimestamp();
    initSync = !loadTimestamp();/*  w  w  w  . j  ava2s  . c o  m*/
    password = "";

    mTimerTask = new Handler();

    dataTask = new SyncDataTask();

    password = Prefs.getSavedPassword(getApplicationContext());

    outgoing = new ArrayList<Map<String, String>>();

    utils = new HttpUtils();

    DBSyncService.version = getString(R.string.VersionID);

    mTimerTask.post(dataTask);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.service_notify_title))
            .setContentText(getString(R.string.service_notify_text)).setOngoing(true).setWhen(0);
    Intent notifyIntent = new Intent(this, DashboardActivity.class);
    notifyIntent.setAction(Intent.ACTION_MAIN);
    notifyIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    mBuilder.setContentIntent(intent);

    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(notifyID, mBuilder.build());
}

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

public static void offlineNotify(Context context, String state) {
    if (state == null)
        state = "";
    Intent i = new Intent(context, RosterActivity.class);
    i.setAction(Intent.ACTION_MAIN);/*w w  w  .  j a  v  a  2  s. c om*/
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, 0);

    JTalkService service = JTalkService.getInstance();
    service.setGlobalState(state);
    context.sendBroadcast(new Intent(Constants.UPDATE));

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
    mBuilder.setSmallIcon(R.drawable.stat_offline);
    mBuilder.setContentTitle(context.getString(R.string.app_name));
    mBuilder.setContentText(state);
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    NotificationManager mng = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mng.notify(NOTIFICATION, mBuilder.build());
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override/*from  w  w  w. j ava2s.co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:at.diamonddogs.util.Utils.java

/**
 * Brings up the MAIN/LAUNCHER activity and clears the top
 *
 * @param context a {@link Context}/*from ww  w  .  j a v a2  s  .  c  o  m*/
 */
public static void returnToHome(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(context.getPackageName());
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    Intent homeIntent = new Intent("android.intent.action.MAIN");
    homeIntent.addCategory("android.intent.category.LAUNCHER");
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    homeIntent.setComponent(new ComponentName(context.getPackageName(), activities.get(0).activityInfo.name));
    context.startActivity(homeIntent);
}

From source file:com.miz.service.MakeAvailableOffline.java

@Override
protected void onHandleIntent(Intent intent) {
    reset();//ww w.  j a va 2s .c o  m

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("mizuu-stop-offline-download"));

    mContext = getApplicationContext();

    String defaultSize = mContext.getString(R.string._16kb);
    String bufferSize = PreferenceManager.getDefaultSharedPreferences(mContext).getString(BUFFER_SIZE,
            defaultSize);
    if (bufferSize.equals(defaultSize))
        mBufferSize = 8192 * 2; // This appears to be the limit for most video players
    else
        mBufferSize = 8192;

    mFileUrl = intent.getExtras().getString(FILEPATH);
    mType = intent.getExtras().getInt(TYPE);

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

    // Set up cancel dialog intent
    Intent notificationIntent = new Intent(this, CancelOfflineDownload.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    mContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setColor(getResources().getColor(R.color.color_primary));
    mBuilder.setOngoing(true);
    mBuilder.setOnlyAlertOnce(true);
    mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
    mBuilder.setContentIntent(mContentIntent);

    String message = getString(R.string.downloadingMovie);
    if (mType == MizLib.TYPE_SHOWS)
        message = getString(R.string.downloadingEpisode);
    mBuilder.setTicker(message);
    mBuilder.setContentTitle(message);

    mBuilder.setContentText(getContentText());
    try {
        int size = MizLib.getThumbnailNotificationSize(mContext);
        mBuilder.setLargeIcon(MizuuApplication.getPicasso(mContext).load(intent.getExtras().getString("thumb"))
                .resize(size, (int) (size * 1.5)).get());
    } catch (IOException ignored) {
    }
    try {
        int width = MizLib.getLargeNotificationWidth(mContext);
        int height = (int) (width / 1.78);
        mBuilder.setStyle(new NotificationCompat.BigPictureStyle().setSummaryText(message)
                .bigPicture(MizuuApplication.getPicasso(getApplicationContext())
                        .load(intent.getExtras().getString("backdrop")).resize(width, height).get()));
    } catch (IOException e) {
    }

    mBuilder.addAction(R.drawable.ic_close_white_24dp, getString(android.R.string.cancel), mContentIntent);

    boolean exists = checkIfNetworkFileExists();

    if (!exists) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mContext, R.string.unavailable_file, Toast.LENGTH_LONG).show();
            }
        });
        stopSelf();
        return;
    }

    boolean ignoreSizeCheck = PreferenceManager.getDefaultSharedPreferences(mContext)
            .getBoolean(IGNORE_FILESIZE_CHECK, false);
    if (!ignoreSizeCheck) {
        boolean sizeOK = checkFilesize();

        if (!sizeOK) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(mContext, R.string.not_enough_space, Toast.LENGTH_LONG).show();
                }
            });
            stopSelf();
            return;
        }
    }

    exists = checkIfLocalCopyExists();
    if (exists) { // There's already an exact local copy - don't download again
        stopSelf();
        return;
    }

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(mContext, R.string.starting_download, Toast.LENGTH_SHORT).show();
        }
    });

    updateNotification();
    startForeground(NOTIFICATION_ID, mNotification);

    boolean success = beginTransfer();

    if (!success) { // Delete the offline file if the transfer wasn't successful
        if (mFileUrl.startsWith("http"))
            FileUtils.getOfflineFile(mContext, mFileUrl).delete();
        else
            FileUtils.getOfflineFile(mContext, mSmb.getCanonicalPath()).delete();
    }
}

From source file:com.playpalgames.app.GcmIntentService.java

private void sendNotification(String notificationMessage, String command) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this.getApplicationContext(), StartActivity_.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.putExtra("COMMAND", command);
    intent.setAction(Long.toString(System.currentTimeMillis()));

    PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ball)
            .setContentTitle("Penalty!").setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMessage))
            .setContentText(notificationMessage);

    mBuilder.setContentIntent(contentIntent);
    Notification note = mBuilder.build();
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.defaults |= Notification.DEFAULT_SOUND;

    mNotificationManager.notify(NOTIFICATION_ID, note);
}

From source file:com.launcher.silverfish.launcher.appdrawer.AppDrawerTabFragment.java

/**
 * Loads apps from the database/*from  w ww . j  a va  2s .co m*/
 */
private void loadApps() {

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

    switch ((int) tabId) {
    case 1:
        // Tab 1 is a special tab and includes all except for the ones in other tabs
        // Retrieve all installed apps on the device
        List<ResolveInfo> availableActivities = mPacMan.queryIntentActivities(i, 0);

        // And only add those that are not in the database
        for (int j = 0; j < availableActivities.size(); j++) {
            ResolveInfo ri = availableActivities.get(j);

            if (sqlHelper.containsApp(ri.activityInfo.packageName))
                continue;

            AppDetail app = new AppDetail();
            app.label = ri.loadLabel(mPacMan);
            app.packageName = ri.activityInfo.packageName;

            // Load the icon later in an async task.
            app.icon = null;

            appsList.add(app);
        }
        break;
    default:
        // All other tabs just query the apps from the database
        List<AppTable> apps = sqlHelper.getAppsForTab(tabId);
        for (AppTable app : apps) {

            boolean success = addAppToList(app.getPackageName());
            // If the app could not be added then it was probably uninstalled,
            // so we have to remove it from the database
            if (!success) {
                Log.d("DB", "Removing app " + app.getPackageName() + " from db");
                sqlHelper.removeAppFromTab(app.getPackageName(), this.tabId);
            }
        }

        // show the empty category notice if this tab is empty
        if (apps.size() == 0) {
            showEmptyCategoryNotice();
        }
    }
}