List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:codepath.watsiapp.utils.Util.java
private static void startShareIntentWithExplicitSocialActivity(Activity ctx, ShareableItem patient, Set<String> socialActivitiesName, String displayName) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, patient.getShareableUrl()); try {/*from w w w . j a v a 2 s . c o m*/ final PackageManager pm = ctx.getPackageManager(); final List activityList = pm.queryIntentActivities(shareIntent, 0); int len = activityList.size(); for (int i = 0; i < len; i++) { final ResolveInfo app = (ResolveInfo) activityList.get(i); Log.d("#####################", app.activityInfo.name); if (socialActivitiesName.contains(app.activityInfo.name)) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Fund Treatment"); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setComponent(name); ctx.startActivity(shareIntent); break; } } } catch (final ActivityNotFoundException e) { Toast.makeText(ctx, "Could not find " + displayName + " app", Toast.LENGTH_SHORT).show(); } }
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 w w .j a va 2 s . c om 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:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate menu from XML resource MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.list_options_menu, menu); Intent intent = new Intent(null, getIntent().getData()); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null, intent, 0, null);/*from w w w . j a v a2 s .c o m*/ return super.onCreateOptionsMenu(menu); }
From source file:com.redhorse.quickstart.AppAll.java
private void loadApps() { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mAllApps = getPackageManager().queryIntentActivities(mainIntent, 0); mApps = new ArrayList<ResolveInfo>(); Cursor c = dbStart.getAllItems(); Iterator it1 = mAllApps.iterator(); while (it1.hasNext()) { ResolveInfo info = (ResolveInfo) it1.next(); if (!info.activityInfo.packageName.equalsIgnoreCase("com.redhorse.quickstart")) mApps.add(info);//from w ww . j av a2s. c o m } c.close(); }
From source file:bander.notepad.NoteListAppCompat.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info; try {/* w w w . j a va 2 s . co m*/ info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { return; } Cursor cursor = (Cursor) getListAdapter().getItem(info.position); if (cursor == null) { return; } menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE)); Uri uri = ContentUris.withAppendedId(getIntent().getData(), cursor.getInt(COLUMN_INDEX_ID)); Intent[] specifics = new Intent[1]; specifics[0] = new Intent(Intent.ACTION_EDIT, uri); MenuItem[] items = new MenuItem[1]; Intent intent = new Intent(null, uri); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items); menu.add(0, DELETE_ID, 0, R.string.menu_delete); // TODO: When you click on this, it crashes. I commented it out for now. // menu.add(0, SEND_ID, 0, R.string.menu_send); }
From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java
private void open(ApplicationInfo item) { // open app//from www .j a v a 2 s.c o m Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(item.packageName); List<ResolveInfo> resolveInfoList = getActivity().getPackageManager().queryIntentActivities(resolveIntent, 0); if (resolveInfoList != null && resolveInfoList.size() > 0) { ResolveInfo resolveInfo = resolveInfoList.get(0); String activityPackageName = resolveInfo.activityInfo.packageName; String className = resolveInfo.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName componentName = new ComponentName(activityPackageName, className); intent.setComponent(componentName); startActivity(intent); } }
From source file:com.example.android.threadsample.BroadcastNotifier.java
/** * * Uses LocalBroadcastManager to send an {@link Intent} containing {@code status}. The * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}. * * @param status {@link Integer} denoting a work request status *//*from w w w . j a v a2 s . com*/ public void broadcastIntentWithState(int status) { Intent localIntent = new Intent(); // The Intent contains the custom broadcast action for this app localIntent.setAction(Constants.BROADCAST_ACTION); // Puts the status into the Intent localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, status); localIntent.addCategory(Intent.CATEGORY_DEFAULT); // Broadcasts the Intent mBroadcaster.sendBroadcast(localIntent); }
From source file:com.google.android.demos.jamendo.app.PlaylistActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); int groupId = MENU_GROUP_INTENT_OPTIONS; int itemId = Menu.NONE; int order = Menu.NONE; ComponentName caller = getComponentName(); Intent[] specifics = null;//ww w . j a va2s . c o m Intent intent = new Intent(); long id = ContentUris.parseId(getIntent().getData()); intent.setDataAndType(JamendoContract.createPlaylistUri(JamendoContract.FORMAT_M3U, Playlists.ID, id), JamendoContract.CONTENT_TYPE_M3U); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); int flags = 0; MenuItem[] outSpecificItems = null; menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems); return menu.hasVisibleItems(); }
From source file:cn.androidy.network.download.BroadcastNotifier.java
/** * Uses LocalBroadcastManager to send an {@link Intent} containing {@code status}. The * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}. * * @param status {@link Integer} denoting a work request status */// w w w .j a v a 2s. com public void broadcastIntentWithState(int status) { Intent localIntent = new Intent(); // The Intent contains the custom broadcast action for this app localIntent.setAction(Constants.BROADCAST_ACTION); // Puts the status into the Intent localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, status); localIntent.addCategory(Intent.CATEGORY_DEFAULT); // Broadcasts the Intent mBroadcaster.sendBroadcast(localIntent); }
From source file:com.gnuroot.rsinstaller.RSLauncherMain.java
/** * GNURoot Debian expects the following extras from install intents: * 1. launchType: This can be either launchTerm or launchXTerm. The command that is to be run after installation * dictates this selection.//ww w . j a v a 2 s . c o m * 2. command: This is the command that will be executed in proot after installation. Often, this will be a * script stored in your custom tar file to install additional packages if needed or to execute the extension. * 3. customTar: This is the custom tar file you've created for your extension. * @return */ private Intent getLaunchIntent() { String command; Intent installIntent = new Intent("com.gnuroot.debian.LAUNCH"); installIntent.setComponent(new ComponentName("com.gnuroot.debian", "com.gnuroot.debian.GNURootMain")); installIntent.addCategory(Intent.CATEGORY_DEFAULT); installIntent.putExtra("launchType", "launchXTerm"); command = "#!/bin/bash\n" + "if [ ! -f /support/.rs_custom_passed ] || [ ! -f /support/.rs_updated ]; then\n" + " /support/untargz rs_custom /support/rs_custom.tar.gz\n" + "fi\n" + "if [ -f /support/.rs_custom_passed ]; then\n" + " if [ ! -f /support/.rs_script_passed ]; then\n" + " sudo /support/blockingScript rs_script /support/oldschoolrs_install.sh\n" + " fi\n" + " if [ ! -f /support/.rs_script_updated ]; then\n" + " sudo mv /support/rs_update /usr/bin/oldschoolrs\n" + " if [ $? == 0 ]; then\n" + " touch /support/.rs_script_updated\n" + " sudo chmod 755 /usr/bin/oldschoolrs\n" + " fi\n" + " fi\n" + " if [ -f /support/.rs_script_passed ]; then\n" + " /usr/bin/oldschoolrs\n" + " fi\n" + "fi\n"; installIntent.putExtra("command", command); installIntent.putExtra("packageName", "com.gnuroot.rsinstaller"); installIntent.putExtra("GNURootVersion", GNURootVersion); installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); installIntent.setData(getTarUri()); return installIntent; }