Example usage for android.content Intent EXTRA_INTENT

List of usage examples for android.content Intent EXTRA_INTENT

Introduction

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

Prototype

String EXTRA_INTENT

To view the source code for android.content Intent EXTRA_INTENT.

Click Source Link

Document

An Intent describing the choices you would like shown with #ACTION_PICK_ACTIVITY or #ACTION_CHOOSER .

Usage

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

private void onFileClicked(final String resourcePath, final String resourceState, final String filename,
        final String data) {
    Log.d(TAG, "onFileClicked() data=" + data);

    final boolean isStateIdle = (resourceState == null);
    boolean isDownloading, isFailedDownload;
    isDownloading = isFailedDownload = false;
    if (!isStateIdle) {
        isDownloading = ResourceState.STATE_GETTING.equals(resourceState);
        isFailedDownload = ResourceState.STATE_GETTING_FAILED.equals(resourceState);
    }//from  ww w . j  a  va  2s  .  c  o m

    final boolean validTarget = MetaUtilities.isValidUriTarget(data);

    Log.d(TAG, String.format("isStateIdle=%s, validTarget=%s", String.valueOf(isStateIdle),
            String.valueOf(validTarget)));
    if (validTarget && isStateIdle) {
        // File exists and is not being downloaded.
        if (data.startsWith(ContentResolver.SCHEME_CONTENT)) {
            Log.d(TAG, "opening file from content uri");

            final Intent intent = new Intent(Intent.ACTION_VIEW);
            final Uri uri = Uri.parse(data);
            intent.setDataAndType(uri, FileUtilities.getMime(filename));

            final Intent chooser = new Intent(Intent.ACTION_VIEW);
            chooser.putExtra(Intent.EXTRA_INTENT, intent);
            chooser.putExtra(Intent.EXTRA_TITLE, getText(R.string.dialog_open_with_title));
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                UIUtil.showToast(this, R.string.toast_no_suitable_activity);
            }
        } else {
            Log.d(TAG, "opening file directly");
            File file = null;
            try {
                Log.d(TAG, "opening " + data);
                if (data.startsWith(ContentResolver.SCHEME_FILE)) {
                    file = new File(URI.create(data));
                } else {
                    file = new File(data);
                }
            } catch (Exception e) {
                Log.e(TAG, "file uri is empty", e);
            }
            if (file != null && file.exists()) {
                Log.d(TAG, "Resource exists, opening: " + file.getAbsolutePath());
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file), FileUtilities.getMime(data));

                Intent chooser = new Intent(Intent.ACTION_VIEW);
                chooser.putExtra(Intent.EXTRA_INTENT, intent);
                chooser.putExtra(Intent.EXTRA_TITLE, getText(R.string.dialog_open_with_title));
                try {
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    UIUtil.showToast(this, R.string.toast_no_suitable_activity);
                }
            } else {
                Log.d(TAG, "Setting resource as not cached: " + resourcePath);
                MetaUtilities.setIsCached(resourcePath, false);
                MetaUtilities.setStateAndData(resourcePath, null, null);
                UIUtil.showToast(this, R.string.toast_file_not_cached_anymore, false);
                mResolver.notifyChange(Nodes.CONTENT_URI, null);
            }
        }
    } else if (isFailedDownload) {
        // File does not exist or download failed.
        Log.d(TAG, "was: failed download or invalid");
        if (NetworkUtil.isConnected(this)) {
            downloadFile(resourcePath);
        } else {
            UIUtil.showToast(this, R.string.toast_no_network);
        }
    } else if (isStateIdle && !validTarget) {
        // File removed from device, need to download.
        downloadFile(resourcePath);
    } else if (isDownloading) {
        UIUtil.showToast(this, "Please wait while downloading...");
    } else {
        Log.e(TAG, "unhandled state: " + resourceState);
    }
}

From source file:com.dish.browser.activity.BrowserActivity.java

@Override
public void showFileChooser(ValueCallback<Uri[]> filePathCallback) {
    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }//from  w w  w  . java  2 s  .  c  o m
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = Utils.createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(Constants.TAG, "Unable to create Image File", ex);
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("image/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[] { takePictureIntent };
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    mActivity.startActivityForResult(chooserIntent, 1);
}

From source file:com.android.launcher2.Launcher.java

void processShortcut(Intent intent) {
    // Handle case where user selected "Applications"
    String applicationName = getResources().getString(R.string.group_applications);
    String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);

    if (applicationName != null && applicationName.equals(shortcutName)) {
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
        pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
        startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
    } else {/*from  w w  w. jav a2  s.  co m*/
        startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {

    PersonaLog.e(LOG_TAG, "processShortcut" + intent);
    // Handle case where user selected "Applications"
    String applicationName = getResources().getString(R.string.group_applications);
    String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);

    if (applicationName != null && applicationName.equals(shortcutName)) {
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        // 290778 modified for shortcut
        /*/*w  w  w  .j ava2s  . co m*/
         * Intent mainIntent = new Intent("Email");
         * mainIntent.addCategory("android.intent.category.PIM");
         */

        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
        pickIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.group_applications));
        startActivityForResult(pickIntent, requestCodeApplication);
    } else {
        startActivityForResult(intent, requestCodeShortcut);
    }
}

From source file:com.android.soma.Launcher.java

void processShortcut(Intent intent) {
    // Handle case where user selected "Applications"
    String applicationName = getResources().getString(R.string.group_applications);
    String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);

    if (applicationName != null && applicationName.equals(shortcutName)) {
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
        pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
        Utilities.startActivityForResultSafely(this, pickIntent, REQUEST_PICK_APPLICATION);
    } else {/*from  w  w w .ja v a 2s.  co  m*/
        Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void pickShortcut(int requestCode, int title) {
    Bundle bundle = new Bundle();
    /*//from w w  w . j a va 2 s  .c  o  m
          ArrayList<String> shortcutNames = new ArrayList<String>();
          shortcutNames.add(getString(R.string.group_applications));
          bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
            
          ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
          shortcutIcons.add(ShortcutIconResource.fromContext(
    PersonaLauncher.this, R.drawable.pr_ic_launcher_application));
          bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    shortcutIcons);*/
    //   Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    Intent pickIntent = new Intent();

    String ShortCutName = new String(getString(R.string.group_applications));
    bundle.putString(Intent.EXTRA_SHORTCUT_NAME, ShortCutName);

    pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
    pickIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.group_applications));
    pickIntent.putExtras(bundle);
    processShortcut(pickIntent, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
    //startActivityForResult(pickIntent, requestCode);
}