Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

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

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.ape.filemanager.FileExplorerTabActivityOld.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_pager);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGES);

    mIsMyOsOptionMenuStyle = getResources().getBoolean(R.bool.myos_option_menu_style);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_category), FileCategoryActivityMyOS.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_sd), FileViewActivity.class, null);
    if (getResources().getBoolean(R.bool.have_cloud_file)) {
        mTabsAdapter.addTab(bar.newTab().setText(R.string.cloud_storage), CloudFileActivity.class, null);
    } else {/*from   w  w w . ja  va  2 s . com*/
        mTabsAdapter.addTab(bar.newTab().setText(R.string.tab_remote), ServerControlActivity.class, null);
    }

    int tabIndex;
    Intent intent = getIntent();
    String action = intent.getAction();
    if (getIntent().getData() != null) {
        tabIndex = Util.SDCARD_TAB_INDEX;
    } else if (!TextUtils.isEmpty(action)) {
        if (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT)
                || action.equals("com.mediatek.filemanager.ADD_FILE")) {
            tabIndex = Util.CATEGORY_TAB_INDEX;
        } else if (action.equals(CloudFileUtil.CLOUD_STORAGE_ACTION)) {
            tabIndex = Util.REMOTE_TAB_INDEX;
        } else {
            tabIndex = Util.CATEGORY_TAB_INDEX;
        }
    } else {
        tabIndex = Util.CATEGORY_TAB_INDEX; //For market require.
        //          tabIndex = PreferenceManager.getDefaultSharedPreferences(this)
        //                  .getInt(INSTANCESTATE_TAB, Util.CATEGORY_TAB_INDEX);
    }
    bar.setSelectedNavigationItem(tabIndex);

    mMountPointManager = MountPointManager.getInstance();
    mMountPointManager.init(this);
}

From source file:org.tanrabad.team.ChatFragment.java

private void initUiComponents(View rootView) {
    mListView = (ListView) rootView.findViewById(R.id.list);
    turnOffListViewDecoration(mListView);
    mListView.setAdapter(mAdapter);/*from   www  . j  a  v a 2 s  .  c  om*/

    mBtnChannel = (ImageButton) rootView.findViewById(R.id.btn_channel);
    mBtnSend = (Button) rootView.findViewById(R.id.btn_send);
    mBtnUpload = (ImageButton) rootView.findViewById(R.id.btn_upload);
    mProgressBtnUpload = (ProgressBar) rootView.findViewById(R.id.progress_btn_upload);
    mEtxtMessage = (EditText) rootView.findViewById(R.id.etxt_message);

    mBtnSend.setEnabled(false);
    mBtnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            send();
        }
    });

    mBtnChannel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mHandler != null) {
                mHandler.onChannelListClicked();
            }
        }
    });

    mBtnUpload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_PICK_IMAGE);
        }
    });

    mEtxtMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    send();
                }
                return true; // Do not hide keyboard.
            }
            return false;
        }
    });
    mEtxtMessage.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEtxtMessage.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mBtnSend.setEnabled(s.length() > 0);
        }
    });
    mListView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            SoftKeyboard.hide(getActivity());
            return false;
        }
    });
    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
                if (view.getFirstVisiblePosition() == 0 && view.getChildCount() > 0
                        && view.getChildAt(0).getTop() == 0) {
                    resultHandler = new MessageListQuery.MessageListQueryResult() {
                        @Override
                        public void onResult(List<MessageModel> messageModels) {
                            for (MessageModel model : messageModels) {
                                mAdapter.addMessageModel(model);
                            }

                            mAdapter.notifyDataSetChanged();
                            mListView.setSelection(messageModels.size());
                        }

                        @Override
                        public void onError(Exception e) {
                        }
                    };
                    SendBird.queryMessageList(SendBird.getChannelUrl()).prev(mAdapter.getMinMessageTimestamp(),
                            30, resultHandler);
                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
}

From source file:org.opendatakit.survey.activities.MediaChooseAudioActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        appName = extras.getString(IntentConsts.INTENT_KEY_APP_NAME);
        tableId = extras.getString(IntentConsts.INTENT_KEY_TABLE_ID);
        instanceId = extras.getString(IntentConsts.INTENT_KEY_INSTANCE_ID);
        uriFragmentNewFileBase = extras.getString(URI_FRAGMENT_NEW_FILE_BASE);
    }/*from   ww  w .j ava  2s .  c  o  m*/

    if (savedInstanceState != null) {
        appName = savedInstanceState.getString(IntentConsts.INTENT_KEY_APP_NAME);
        tableId = savedInstanceState.getString(IntentConsts.INTENT_KEY_TABLE_ID);
        instanceId = savedInstanceState.getString(IntentConsts.INTENT_KEY_INSTANCE_ID);
        uriFragmentNewFileBase = savedInstanceState.getString(URI_FRAGMENT_NEW_FILE_BASE);
    }

    if (appName == null) {
        throw new IllegalArgumentException(
                "Expected " + IntentConsts.INTENT_KEY_APP_NAME + " key in intent bundle. Not found.");
    }

    if (tableId == null) {
        throw new IllegalArgumentException(
                "Expected " + IntentConsts.INTENT_KEY_TABLE_ID + " key in intent bundle. Not found.");
    }
    if (instanceId == null) {
        throw new IllegalArgumentException(
                "Expected " + IntentConsts.INTENT_KEY_INSTANCE_ID + " key in intent bundle. Not found.");
    }

    if (uriFragmentNewFileBase == null) {
        throw new IllegalArgumentException(
                "Expected " + URI_FRAGMENT_NEW_FILE_BASE + " key in intent bundle. Not found.");
    }

    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType(MEDIA_CLASS + "*");
    try {
        startActivityForResult(i, ACTION_CODE);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this,
                getString(R.string.activity_not_found, Intent.ACTION_GET_CONTENT + " " + MEDIA_CLASS),
                Toast.LENGTH_SHORT).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
}

From source file:org.alfresco.mobile.android.platform.intent.BaseActionUtils.java

/**
 * Allow to pick file with other apps.// w  ww  .j  av  a  2s.c  o m
 * 
 * @return Activity for Result.
 */
public static void actionPickFile(Fragment f, int requestCode) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("*/*");
    i.addCategory(Intent.CATEGORY_OPENABLE);
    f.startActivityForResult(Intent.createChooser(i, f.getText(R.string.content_app_pick_file)), requestCode);
}

From source file:com.accia77.mockey.ui.PickBackgroundImagesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pick_background_images);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // get the large image view
    picView = (ImageView) findViewById(R.id.picture);

    // get the gallery view
    picGallery = (Gallery) findViewById(R.id.gallery);

    // create a new adapter
    imgAdapt = new PicAdapter(this);

    // set the gallery adapter
    picGallery.setAdapter(imgAdapt);/*from w ww  .  ja v a 2 s  .c om*/

    // set long click listener for each gallery thumbnail item
    picGallery.setOnItemLongClickListener(new OnItemLongClickListener() {
        // handle long clicks
        public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
            // take user to choose an image
            // update the currently selected position so that we assign the
            // imported bitmap to correct item

            // take the user to their chosen image selection app (gallery or
            // file manager)
            Intent pickIntent = new Intent();
            pickIntent.setType("image/*");
            pickIntent.setAction(Intent.ACTION_GET_CONTENT);

            // position's value if the request code for startActivityForResult
            startActivityForResult(Intent.createChooser(pickIntent,
                    getResources().getString(R.string.select_background_image)), position);

            return true;

        }
    });

    // set the click listener for each item in the thumbnail gallery
    picGallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // set the larger image view to display the chosen bitmap
            // calling method of adapter class
            picView.setImageBitmap(imgAdapt.getPic(position));
        }
    });

}

From source file:com.monmonja.library.social.SocialNetworkDialogFragment.java

@Override
public void onClick(View v) {
    if (v.equals(mTakePhotoBtn)) {
        dispatchTakePictureIntent();/*www. j  a va2 s  .  com*/
    } else if (v.equals(mPickPhotoBtn)) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, RESULT_SELECT_PHOTO);
    }
}

From source file:com.pixby.texo.images.ImageUtil.java

public static void getImageFromGallery(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    activity.startActivityForResult(Intent.createChooser(intent, "Choose Photo"), ImageUtil.PICK_IMAGE_REQUEST);
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Fragment fragment, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = fragment.getActivity().getPackageManager();
    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(fragment.getString(R.string.actfm_picture_camera));

    options.add(fragment.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(fragment.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getActivity(),
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override/* ww w .java2 s. c om*/
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(fragment.getActivity());
                if (lastTempFile != null)
                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                fragment.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                fragment.startActivityForResult(
                        Intent.createChooser(intent, fragment.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(fragment.getActivity()).setAdapter(adapter, listener).show()
            .setOwnerActivity(fragment.getActivity());
}

From source file:org.sufficientlysecure.keychain.util.FileHelper.java

/** Opens the preferred installed file manager on Android and shows a toast
 * if no manager is installed. */
private static void openDocumentPreKitKat(Fragment fragment, Uri last, String mimeType, boolean multiple,
        int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
    }/*  ww w . j a va2  s.  co  m*/
    intent.setData(last);
    intent.setType(mimeType);

    try {
        fragment.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        // No compatible file manager was found.
        Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT).show();
    }

}

From source file:com.ape.filemanager.FileExplorerTabActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    if (actionBar != null)
        actionBar.hide();//from  ww w  .ja v a  2s .c  om

    setContentView(R.layout.myos_activity_main);

    mMountPointManager = MountPointManager.getInstance();
    mMountPointManager.init(this);

    initTabTitles();
    mFragmentAdapter = new FileManagerFragmentAdapter(getFragmentManager(), this);
    restoreOrCreateFragment(savedInstanceState);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mFragmentAdapter);
    mViewPager.setOffscreenPageLimit(DEFAULT_OFFSCREEN_PAGES);

    mTagPagerIndicator = (TabPageIndicator) findViewById(R.id.indicator);
    mTagPagerIndicator.setViewPager(mViewPager);
    mTagPagerIndicator.setOnPageChangeListener(mPageChangeListener);

    int tabIndex;
    Intent intent = getIntent();
    String action = intent.getAction();
    if (getIntent().getData() != null) {
        tabIndex = Util.SDCARD_TAB_INDEX;
    } else if (!TextUtils.isEmpty(action)) {
        if (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT)
                || action.equals("com.mediatek.filemanager.ADD_FILE")) {
            tabIndex = Util.CATEGORY_TAB_INDEX;
        } else if (action.equals(CloudFileUtil.CLOUD_STORAGE_ACTION)) {
            tabIndex = Util.REMOTE_TAB_INDEX;
        } else {
            tabIndex = Util.CATEGORY_TAB_INDEX;
        }
    } else {
        tabIndex = Util.CATEGORY_TAB_INDEX; //For market require.
        //          tabIndex = PreferenceManager.getDefaultSharedPreferences(this)
        //                  .getInt(INSTANCESTATE_TAB, Util.CATEGORY_TAB_INDEX);
        mHandler.sendEmptyMessageDelayed(MSG_UPDATE_VERSION, 3000);
    }
    mTagPagerIndicator.setCurrentItem(tabIndex);

    upgradeManger = UpgradeManager.newInstance(this, getApplicationInfo().packageName,
            getString(R.string.app_name));
}