Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:io.ingame.squarecamera.CameraLauncher.java

/**
 * Get image from photo library.// w  ww. j  ava  2s . c  o m
 *
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 * @param encodingType
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            setOutputUri(intent, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this,
                Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

private List<ResolveInfo> getAllLauncherIntentResolversSorted() {
    final Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> launcherIntentResolvers = mPackageManager.queryIntentActivities(launcherIntent, 0);
    Collections.sort(launcherIntentResolvers, new ResolveInfo.DisplayNameComparator(mPackageManager));
    return launcherIntentResolvers;
}

From source file:android_network.hetnet.vpn_service.ActivitySettings.java

private Intent getIntentCreateExport() {
    Intent intent;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (Util.isPackageInstalled("org.openintents.filemanager", this)) {
            intent = new Intent("org.openintents.action.PICK_DIRECTORY");
        } else {//w  ww  .  ja va2  s  .c  om
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(
                    Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager"));
        }
    } else {
        intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*"); // text/xml
        intent.putExtra(Intent.EXTRA_TITLE,
                "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml");
    }
    return intent;
}

From source file:com.cordova.photo.CameraLauncher.java

/**
 * Get image from photo library./*  w  w w  . j a va2  s  . c o m*/
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 * @param encodingType 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.activity != null) {
        this.activity.startActivityForResult(Intent.createChooser(intent, new String(title)),
                (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Shows a list of primary user apps in a dialog.
 *
 * @param dialogTitle the title to show for the dialog
 * @param callback will be called with the list apps that the user has selected when he closes
 *        the dialog. The callback is not fired if the user cancels.
 *//*from ww w.j  a  v  a 2s . c  om*/
private void showManageLockTaskListPrompt(int dialogTitle, final ManageLockTaskListCallback callback) {
    if (getActivity() == null || getActivity().isFinishing()) {
        return;
    }
    Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> primaryUserAppList = mPackageManager.queryIntentActivities(launcherIntent, 0);
    if (primaryUserAppList.isEmpty()) {
        showToast(R.string.no_primary_app_available);
    } else {
        Collections.sort(primaryUserAppList, new ResolveInfo.DisplayNameComparator(mPackageManager));
        final LockTaskAppInfoArrayAdapter appInfoArrayAdapter = new LockTaskAppInfoArrayAdapter(getActivity(),
                R.id.pkg_name, primaryUserAppList);
        ListView listView = new ListView(getActivity());
        listView.setAdapter(appInfoArrayAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                appInfoArrayAdapter.onItemClick(parent, view, position, id);
            }
        });

        new AlertDialog.Builder(getActivity()).setTitle(getString(dialogTitle)).setView(listView)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String[] lockTaskEnabledArray = appInfoArrayAdapter.getLockTaskList();
                        callback.onPositiveButtonClicked(lockTaskEnabledArray);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
    }
}

From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java

@Override
public void updateEditedIntent(Intent editedIntent) {
    // Intent action

    if (mAvailbleActions != null) {
        editedIntent.setAction((String) mActionsSpinner.getSelectedItem());
    } else {/*w w  w .j a  v  a 2 s.  c  om*/
        String action = mActionText.getText().toString();
        if ("".equals(action)) {
            action = null;
        }
        editedIntent.setAction(action);
    }

    // Categories
    {
        // Clear categories (why there's no api for this)
        Set<String> origCategories = editedIntent.getCategories();
        if (origCategories != null) {
            for (String category : origCategories.toArray(new String[origCategories.size()])) {
                editedIntent.removeCategory(category);
            }
        }
    }
    // Fill categories
    if (mCategoryCheckBoxes != null) {
        // Fill categories from checkboxes
        for (CheckBox cb : mCategoryCheckBoxes) {
            String category = (String) cb.getTag();
            if (cb.isChecked()) {
                editedIntent.addCategory(category);
            }
        }
    } else {
        // Fill categories from textfields
        for (TextView categoryTextView : mCategoryTextInputs) {
            editedIntent.addCategory(categoryTextView.getText().toString());
        }
    }

    // Intent data (Uri) and type (MIME)
    String data = mDataText.getText().toString();
    editedIntent.setDataAndType(data.equals("") ? null : Uri.parse(data), getDataType());

    // Package name
    {
        String packageName = mPackageNameText.getText().toString();
        if ("".equals(packageName)) {
            editedIntent.setPackage(null);
        } else {
            editedIntent.setPackage(packageName);
        }
    }

    // Set component for explicit intent
    updateIntentComponent();
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

private void initViews() {
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    if (wm.getDefaultDisplay().getOrientation() == 0)
        setContentView(R.layout.upload_portrait);
    else/*from www . j  a v a  2s.c o m*/
        setContentView(R.layout.upload_landscape);

    EditText uploadTarget = (EditText) findViewById(R.id.upload_target);
    EditText uploadTitle = (EditText) findViewById(R.id.upload_title);
    EditText uploadText = (EditText) findViewById(R.id.upload_text);
    Button uploadVisit = (Button) findViewById(R.id.upload_visit);
    Button uploadPhotoTake = (Button) findViewById(R.id.upload_photo_take);
    Button uploadPhotoAdd = (Button) findViewById(R.id.upload_photo_add);
    Button uploadPhotoDelete = (Button) findViewById(R.id.upload_photo_delete);
    CheckBox uploadEnclosePosition = (CheckBox) findViewById(R.id.upload_enclose_position);
    Button uploadOk = (Button) findViewById(R.id.upload_ok);
    Button uploadCancel = (Button) findViewById(R.id.upload_cancel);

    /* set button behavior */

    if (passThrough)
        uploadTarget.setClickable(false);
    else {
        uploadTarget.setClickable(true);
        registerForContextMenu(uploadTarget);
    }

    uploadTarget.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!passThrough)
                openContextMenu(v);
        }
    });

    registerForContextMenu(uploadVisit);
    uploadVisit.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            openContextMenu(v);
        }
    });

    uploadPhotoTake.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                tempFile = File.createTempFile("dcuploader_photo_", ".jpg");
            } catch (IOException e) {
                Toast.makeText(ActivityUploader.this, " ??   .",
                        Toast.LENGTH_SHORT).show();

                tempFile = null;

                return;
            }

            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (tempFile != null)
                i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));

            startActivityForResult(i, Application.ACTION_TAKE_PHOTO);
        }
    });

    uploadPhotoAdd.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");
            i.addCategory(Intent.CATEGORY_DEFAULT);

            startActivityForResult(i, Application.ACTION_ADD_PHOTO);
        }
    });

    uploadPhotoDelete.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Gallery g = (Gallery) findViewById(R.id.upload_images);

            int pos = g.getSelectedItemPosition();
            if (pos == -1)
                return;

            contents.remove(pos);
            bitmaps.remove(pos);

            updateGallery();
            updateImageButtons();

            if (contents.size() == 0)
                pos = -1;
            else if (pos >= contents.size())
                --pos;

            g.setSelection(pos);
        }
    });

    uploadOk.setOnClickListener(proceedHandler);

    uploadCancel.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

    uploadEnclosePosition.setChecked(formLocation);

    uploadEnclosePosition.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            locationEnabled = isChecked;

            queryLocation(isChecked);
        }
    });

    /* restore data when orientation changes */
    if (formGallery != null) {
        if (target != null) {
            uploadTarget.setText(formGallery);
            formGallery = null;
        }
    }

    if (formTitle != null) {
        uploadTitle.setText(formTitle);
        formTitle = null;
    }

    if (formBody != null) {
        uploadText.setText(formBody);
        formBody = null;
    }

    updateImageButtons();
    updateGallery();
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

@Override
public void onClick(View view) {
    CellInfo cellInfo = (CellInfo) view.getTag();

    //      Log.i("jim", "1111111111111=======cellInfo.packageName = "+cellInfo.packageName);

    if (cellInfo != null && mLauncherModel != null) {
        //         Log.i("jim", "22222222222=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_QQ)
                && SharedPreUtil.isFirstRunQQ(Constants.PACKAGE_QQ)) {
            LauncherApp.gIsFirstRunQQ = true;
            SharedPreUtil.saveQQVersionNum(Constants.PACKAGE_QQ);
            if (!OrientatorService.mIsClose) {
                OrientatorService.closeOrientatorMode();
            }// www .ja v a  2s.c  om
        } else if (cellInfo.portrait.equals("true")) {
            if (LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) {
                if (!OrientatorService.mIsClose) {
                    OrientatorService.closeOrientatorMode();
                }
            }

        } else {
            if (OrientatorService.mIsClose) {
                OrientatorService.forceLandscapeMode();
            }
        }
        //         Log.i("jim", "3333333=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_VODTYPE)) {
            mLauncherModel.startVstByType(cellInfo.className, Constants.PACKAGE_VODTYPE);
            //            Log.i("jim", "4444444444444=======cellInfo.packageName = "+cellInfo.packageName);

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_VST_RECORD)
                || cellInfo.packageName.equals(Constants.PACKAGE_VST_SETTING)) {
            mLauncherModel.startActivityByAction(cellInfo.packageName);
            //            Log.i("jim", "5555555555=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_GALLERY)) {
            if (cellInfo.className.equals(Constants.PACKAGE_CAMERA)) {
                //               Log.i("jim", "66666666666=======cellInfo.packageName = "+cellInfo.packageName);
                try {
                    ComponentName componentName = new ComponentName(Constants.PACKAGE_GALLERY,
                            Constants.PACKAGE_CAMERA);
                    Intent intent = new Intent();
                    intent.setComponent(componentName);
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(this, cellInfo.packageName + " not found", Toast.LENGTH_SHORT).show();
                }
            } else {
                mLauncherModel.startThirdApk(Constants.PACKAGE_GALLERY, cellInfo.className);
                //               Log.i("jim", "7777777777777777=======cellInfo.packageName = "+cellInfo.packageName);
            }

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_OCOCCI_VIDEO)) {
            //            Log.i("jim", "AAAAAAAAAAAA=======cellInfo.packageName = "+cellInfo.packageName);
            //if(cellInfo.className.equals("tv")){               

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName cn = new ComponentName(Constants.PACKAGE_OCOCCI_VIDEO,
                    "com.ococci.video.activity.WelcomeActivity");
            intent.putExtra("video_request_flag", cellInfo.className);
            intent.setComponent(cn);
            startActivity(intent);

            //}
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_HEALTH)) {
            Intent intent = new Intent();
            intent.setAction("com.vst.allwinner.intent.action.ChannelActivity");
            intent.putExtra("cid", cellInfo.className);//
            startActivity(intent);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_CHILDREN)) {

            Intent intent = new Intent();
            intent.setAction("myvst.intent.action.children.list.v2");
            intent.putExtra("uuid", "424C4C7347456F6F1CF462");
            intent.putExtra("playerIndex", 1);
            startActivity(intent);
        } else if (cellInfo.className != null && !cellInfo.className.equals("")) {
            mLauncherModel.startActivity(cellInfo.packageName, cellInfo.className);

            //            Log.i("jim", "88888888888=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_LIVE)) {
            //            Log.i("jim", "999999999999999=======cellInfo.packageName = "+cellInfo.packageName);
            if (mLiveAppAuthorized) {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            } else {
                CustomToast.showToast(this, R.string.live_unauthorized);
            }
        } else if (cellInfo.packageName.equals("com.allwinner.theatreplayer.launcher.AllAppActivity")) {
            //             Log.i("Trim", cellInfo.packageName);

            Intent intent = new Intent(LaunchActivity.this, LocalAppActivity.class);
            startActivity(intent);
        } else if (cellInfo.packageName.equals("com.android.settings")) {
            //R16settings
            if (Utils.isPkgInstalled(LaunchActivity.this, Constants.PACKAGE_SETTINGS)) {
                mLauncherModel.startThirdApk(Constants.PACKAGE_SETTINGS);
            } else {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            }
        } else {
            //            Log.i("Trim", cellInfo.packageName);
            mLauncherModel.startThirdApk(cellInfo.packageName);
        }
    }
}

From source file:com.fsck.k9.activity.Accounts.java

private void onImport() {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");

    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> infos = packageManager.queryIntentActivities(i, 0);

    if (infos.size() > 0) {
        startActivityForResult(Intent.createChooser(i, null), ACTIVITY_REQUEST_PICK_SETTINGS_FILE);
    } else {/*www.ja  v  a  2  s .  co m*/
        showDialog(DIALOG_NO_FILE_MANAGER);
    }
}

From source file:com.remobile.camera.CameraLauncher.java

/**
 * Get image from photo library.//from www .  ja  v  a2s  .c o m
 *
 * @param quality      Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType      The album to get image from.
 * @param returnType   Set the type of image to return.
 * @param encodingType
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this,
                Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1);
    }
}