Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

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

Prototype

String ACTION_PICK

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

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:com.docd.purefm.ui.fragments.BrowserFragment.java

private void initList(@NonNull final LayoutInflater inflater, @NonNull final View parent) {
    final AbstractBrowserActivity context = getBrowserActivity();

    if (mListView != null) {
        final View emptyView = mListView.getEmptyView();
        if (emptyView != null) {
            emptyView.setVisibility(View.GONE);
        }// w  ww  .j a  v a2  s . c  o m
        mListView.setVisibility(View.GONE);
    }

    final Settings settings = Settings.getInstance(context);

    final ViewGroup listContainer = (ViewGroup) parent.findViewById(R.id.list_container);
    if (listContainer == null) {
        throw new RuntimeException("parent should contain ViewGroup with id R.id.list_container");
    }

    final View swipeRefreshList;
    switch (settings.getListAppearance()) {
    case LIST:
        swipeRefreshList = inflater.inflate(R.layout.browser_listview, listContainer);
        break;

    case GRID:
        swipeRefreshList = inflater.inflate(R.layout.browser_gridview, listContainer);
        break;

    default:
        throw new IllegalArgumentException("Unexpected ListAppearance: " + settings.getListAppearance());
    }

    if (swipeRefreshList == null) {
        throw new RuntimeException("Inflated View is null");
    }

    mMainProgress = parent.findViewById(android.R.id.progress);
    mSwipeRefreshLayoutList = (SwipeRefreshLayout) swipeRefreshList
            .findViewById(R.id.browser_list_swipe_refresh);

    mSwipeRefreshLayoutEmpty = (SwipeRefreshLayout) parent.findViewById(android.R.id.empty);

    mListView = (AbsListView) mSwipeRefreshLayoutList.getChildAt(0);
    if (mListView instanceof ListView) {
        mAdapter = new BrowserListAdapter(context);
    } else {
        mAdapter = new BrowserGridAdapter(context);
    }

    menuController.setBrowserAdapter(this.mAdapter);

    mListView.setEmptyView(parent.findViewById(android.R.id.empty));
    mListView.setAdapter(this.mAdapter);
    final View emptyView = mListView.getEmptyView();
    if (emptyView != null) {
        emptyView.setVisibility(View.GONE);
    }
    mListView.setVisibility(View.GONE);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            final GenericFile target = (GenericFile) (av.getItemAtPosition(pos));
            if (target == null) {
                throw new RuntimeException("onItemClick(): item at position is null");
            }
            if (target.isDirectory()) {
                mBrowser.navigate(target, true);
            } else {
                final AbstractBrowserActivity activity = getBrowserActivity();
                if (activity.getGetContentMimeType() == null) {
                    PFMFileUtils.openFileInExternalApp(activity, target.toFile());
                } else {
                    final Intent intent = new Intent();
                    intent.setData(getResultUriForFileFromIntent(activity.getContentResolver(), target.toFile(),
                            activity.getIntent()));
                    activity.setResult(Activity.RESULT_OK, intent);
                    activity.finish();
                }
            }
        }

        /*
         * Copyright (C) 2013 The CyanogenMod Project
         *
         * Licensed under the Apache License, Version 2.0 (the "License");
         * you may not use this file except in compliance with the License.
         * You may obtain a copy of the License at
         *
         *      http://www.apache.org/licenses/LICENSE-2.0
         *
         * Unless required by applicable law or agreed to in writing, software
         * distributed under the License is distributed on an "AS IS" BASIS,
         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         * See the License for the specific language governing permissions and
         * limitations under the License.
         */
        private Uri getResultUriForFileFromIntent(ContentResolver cr, File src, Intent intent) {
            // Try to find the preferred uri scheme
            Uri result = MediaHelper.fileToContentUri(cr, src);
            if (result == null) {
                result = Uri.fromFile(src);
            }

            if (Intent.ACTION_PICK.equals(intent.getAction()) && intent.getData() != null) {
                final String scheme = intent.getData().getScheme();
                if (scheme != null) {
                    result = result.buildUpon().scheme(scheme).build();
                }
            }

            return result;
        }
    });

    mListView.setChoiceMode(context.getGetContentMimeType() == null ? AbsListView.CHOICE_MODE_MULTIPLE_MODAL
            : AbsListView.CHOICE_MODE_NONE);

    mSwipeRefreshLayoutList.setOnRefreshListener(this);
    mSwipeRefreshLayoutEmpty.setOnRefreshListener(this);

    final int color2resId = settings.getTheme() == Settings.Theme.LIGHT ? R.color.holo_light_window_background
            : R.color.holo_dark_window_background;
    mSwipeRefreshLayoutList.setColorScheme(R.color.holo_light_selected, color2resId,
            R.color.holo_light_selected, color2resId);
    mSwipeRefreshLayoutEmpty.setColorScheme(R.color.holo_light_selected, color2resId,
            R.color.holo_light_selected, color2resId);
}

From source file:org.cafemember.messenger.mytg.fragments.TransfareActivity.java

private void getContacts() {
    Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
    startActivityForResult(intent, PICK_CONTACT);
}

From source file:com.android.music.AlbumBrowserActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
    intent.putExtra("album", Long.valueOf(id).toString());
    intent.putExtra("artist", mArtistId);
    startActivity(intent);//from w  w  w . j a  v  a  2 s. c  om
}

From source file:com.liquid.wallpapers.free.ScroidWallpaperGallery.java

private void recommendWallpaper() {
    if (this.selectedWallpaper == null) {
        return;/* w  w w  .j  a v  a2 s.  c  om*/
    }

    Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
    this.startActivityForResult(intent, PICK_CONTACT);
}

From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java

/**
 * Create various dialog/*from w  ww.j ava 2 s . c  o  m*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddCheckinActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete checkin
                deleteCheckins();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:net.jongrakko.zipsuri.activity.PostUploadActivity.java

private void pickVideo() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(android.provider.MediaStore.Video.Media.CONTENT_TYPE);
    intent.setData(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, PICK_VIDEO_FOR_AVATAR);

}

From source file:org.y20k.transistor.MainActivityFragment.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    switch (requestCode) {
    case PERMISSION_REQUEST_READ_EXTERNAL_STORAGE: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // permission granted - get system picker for images
            Intent pickImageIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(pickImageIntent, REQUEST_LOAD_IMAGE);
        } else {/*from   w  w  w  .java2s  .  c  o m*/
            // permission denied
        }
    }
    }
}

From source file:com.money.manager.ex.fragment.PayeeListFragment.java

private void showDialogEditPayeeName(final SQLTypeTransaction type, final int payeeId, final String payeeName) {
    View viewDialog = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_new_edit_payee, null);
    final EditText edtPayeeName = (EditText) viewDialog.findViewById(R.id.editTextPayeeName);

    edtPayeeName.setText(payeeName);/*  w  w  w  .ja  v  a2  s  .  c  o  m*/
    if (!TextUtils.isEmpty(payeeName)) {
        edtPayeeName.setSelection(payeeName.length());
    }

    new AlertDialogWrapper(getContext()).setView(viewDialog)
            .setIcon(FontIconDrawable.inflate(getContext(), R.xml.ic_user)).setTitle(R.string.edit_payeeName)
            .setPositiveButton(android.R.string.ok, new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    // take payee name from the input field.
                    String name = edtPayeeName.getText().toString();

                    PayeeService service = new PayeeService(mContext);

                    // check if action in update or insert
                    switch (type) {
                    case INSERT:
                        Payee payee = service.createNew(name);
                        if (payee != null) {
                            // Created a new payee. But only if picking a payee for another activity.
                            if (mAction.equalsIgnoreCase(Intent.ACTION_PICK)) {
                                // Select it and close.
                                sendResultToActivity(payee.getId(), name);
                                return;
                            }
                        } else {
                            // error inserting.
                            Toast.makeText(mContext, R.string.db_insert_failed, Toast.LENGTH_SHORT).show();
                        }
                        break;
                    case UPDATE:
                        int updateResult = service.update(payeeId, name);
                        if (updateResult <= 0) {
                            Toast.makeText(mContext, R.string.db_update_failed, Toast.LENGTH_SHORT).show();
                        }
                        break;
                    case DELETE:
                        break;
                    default:
                        break;
                    }
                    // restart loader
                    restartLoader();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).create().show();
}

From source file:openscience.crowdsource.video.experiments.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
    setContentView(R.layout.activity_main);
    setTaskBarColored(this);

    Button consoleButton = (Button) findViewById(R.id.btn_consoleMain);
    consoleButton.setOnClickListener(new View.OnClickListener() {
        @Override/* ww  w  . ja v  a2s.  c o  m*/
        public void onClick(View v) {
            Intent logIntent = new Intent(MainActivity.this, ConsoleActivity.class);
            startActivity(logIntent);
        }
    });

    Button infoButton = (Button) findViewById(R.id.btn_infoMain);
    infoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent aboutIntent = new Intent(MainActivity.this, InfoActivity.class);
            startActivity(aboutIntent);
        }
    });

    initConsole();

    startStopCam = (Button) findViewById(R.id.btn_capture);
    startStopCam.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            createDirIfNotExist(externalSDCardOpenscienceTmpPath);
            String takenPictureFilPath = String.format(
                    externalSDCardOpenscienceTmpPath + File.separator + "%d.jpg", System.currentTimeMillis());
            AppConfigService.updateActualImagePath(takenPictureFilPath);
            Intent aboutIntent = new Intent(MainActivity.this, CaptureActivity.class);
            startActivity(aboutIntent);
        }
    });

    recognize = (Button) findViewById(R.id.suggest);
    recognize.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final RecognitionScenario recognitionScenario = RecognitionScenarioService
                    .getSelectedRecognitionScenario();
            if (recognitionScenario == null) {
                AppLogger.logMessage(" Please select an image recognition scenario first! \n");
                return;
            }

            if (recognitionScenario.getState() == RecognitionScenario.State.NEW) {
                AlertDialog.Builder clarifyDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                clarifyDialogBuilder
                        .setMessage(Html.fromHtml("Please download this scenario first or select another one."))
                        .setCancelable(false)
                        .setPositiveButton("continue", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                LoadScenarioFilesAsyncTask loadScenarioFilesAsyncTask = new LoadScenarioFilesAsyncTask();
                                loadScenarioFilesAsyncTask.execute(recognitionScenario);
                                recognitionScenario.setLoadScenarioFilesAsyncTask(loadScenarioFilesAsyncTask);
                                Intent mainIntent = new Intent(MainActivity.this, ScenariosActivity.class);
                                startActivity(mainIntent);
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                final AlertDialog clarifyDialog = clarifyDialogBuilder.create();
                clarifyDialog.show();
                return;
            }

            if (recognitionScenario.getState() == RecognitionScenario.State.DOWNLOADING_IN_PROGRESS) {
                AlertDialog.Builder clarifyDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                clarifyDialogBuilder.setMessage(Html.fromHtml("Download is in progress, please wait ..."))
                        .setCancelable(false)
                        .setPositiveButton("continue", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                final AlertDialog clarifyDialog = clarifyDialogBuilder.create();
                clarifyDialog.show();
                return;
            }

            if (isCameraStarted) {
                captureImageFromCameraPreviewAndPredict(true);
                return;
            }

            // Call prediction
            predictImage(AppConfigService.getActualImagePath());
        }
    });

    final View selectedScenarioTopBar = findViewById(R.id.selectedScenarioTopBar);
    selectedScenarioTopBar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent selectScenario = new Intent(MainActivity.this, ScenariosActivity.class);
            startActivity(selectScenario);

        }
    });
    selectedScenarioTopBar.setEnabled(false);

    final TextView selectedScenarioText = (TextView) findViewById(R.id.selectedScenarioText);
    selectedScenarioText.setText(PRELOADING_TEXT);

    imageView = (ImageView) findViewById(R.id.imageView1);

    btnOpenImage = (Button) findViewById(R.id.btn_ImageOpen);
    btnOpenImage.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, REQUEST_IMAGE_SELECT);
        }
    });

    // Lazy preload scenarios
    RecognitionScenarioService.initRecognitionScenariosAsync(new RecognitionScenarioService.ScenariosUpdater() {
        @Override
        public void update() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    RecognitionScenario selectedRecognitionScenario = RecognitionScenarioService
                            .getSelectedRecognitionScenario();
                    selectedScenarioText.setText(selectedRecognitionScenario.getTitle());
                    updateViewFromState();
                }
            });
        }
    });

    SharedPreferences sharedPreferences = getSharedPreferences(
            AppConfigService.CROWDSOURCE_VIDEO_EXPERIMENTS_ON_ANDROID_PREFERENCES, MODE_PRIVATE);
    if (sharedPreferences.getBoolean(AppConfigService.SHARED_PREFERENCES, true)) {
        AppLogger.logMessage(welcome);
        sharedPreferences.edit().putBoolean(AppConfigService.SHARED_PREFERENCES, false).apply();
    }

    this.glSurfaceView = new GLSurfaceView(this);
    this.glSurfaceView.setRenderer(this);
    ((ViewGroup) imageView.getParent()).addView(this.glSurfaceView);

    initAppConfig(this);

    client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

    final TextView resultPreviewText = (TextView) findViewById(R.id.resultPreviewtText);
    resultPreviewText.setText(AppConfigService.getPreviewRecognitionText());
    AppConfigService.registerPreviewRecognitionText(new AppConfigService.Updater() {
        @Override
        public void update(final String message) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    View imageButtonsBar = (View) findViewById(R.id.imageButtonBar);
                    imageButtonsBar.setVisibility(View.VISIBLE);
                    imageButtonsBar.setEnabled(true);
                    resultPreviewText.setText(message);
                }
            });

        }
    });
    updateViewFromState();
}

From source file:metrocasas.projectsgt.MainActivity.java

public void openGallery() {
    Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAGE);
}