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:bander.notepad.NoteListAppCompat.java

public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Uri uri = ContentUris.withAppendedId(getIntent().getData(), id);

    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
        setResult(RESULT_OK, new Intent().setData(uri).setClassName(getApplicationContext().getPackageName(),
                "bander.notepad.NoteEditAppCompat"));
    } else {//from  www  .j  a va2s .  com
        startActivity(new Intent(Intent.ACTION_EDIT, uri).setClassName(getApplicationContext().getPackageName(),
                "bander.notepad.NoteEditAppCompat"));
    }
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();// w  ww .ja v a  2  s.c  om
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) SonetCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.adaway.ui.lists.ListsFragment.java

/**
 * Import user lists backup file by showing a file picker.
 *//*from  ww w . j a  v  a  2s. c o  m*/
private void importLists() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    // Start file picker activity
    try {
        this.startActivityForResult(intent, ImportExportHelper.REQUEST_CODE_IMPORT);
    } catch (ActivityNotFoundException exception) {
        // Show dialog to install file picker
        FragmentManager fragmentManager = this.getFragmentManager();
        if (fragmentManager != null) {
            ActivityNotFoundDialogFragment
                    .newInstance(R.string.no_file_manager_title, R.string.no_file_manager,
                            "market://details?id=org.openintents.filemanager", "OI File Manager")
                    .show(fragmentManager, "notFoundDialog");
        }
    }
}

From source file:com.google.plus.samples.photohunt.ThemeViewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_upload:
        startCameraIntent();//from  w  w  w.  j a  v a2s  .  c o m
        return true;

    case R.id.menu_item_gallery:
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Photo"), REQUEST_CODE_IMAGE_SELECT);
        return true;

    case android.R.id.home:
    case R.id.menu_item_theme_select:
        DialogFragment themeDialog = new ThemeSelectDialog();
        themeDialog.show(getSupportFragmentManager(), SELECT_THEME_TAG);
        return true;

    case R.id.menu_item_profile:
        Intent profileIntent = new Intent();
        profileIntent.setClass(this, ProfileActivity.class);
        startActivity(profileIntent);
        return true;

    case R.id.menu_item_refresh:
        mThemeListLoader.forceLoad();
        mPhotoListAdapter.setDirty(THEME_PHOTOS_ID, true);
        mPhotoListAdapter.setDirty(FRIEND_PHOTOS_ID, true);
        mPhotoListAdapter.setDirty(MY_PHOTOS_ID, true);
        update();
        return true;

    case R.id.menu_item_about:
        Intent aboutIntent = new Intent();
        aboutIntent.setClass(this, AboutActivity.class);
        startActivity(aboutIntent);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:it.rignanese.leo.slimfacebook.MainActivity.java

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

    // setup the sharedPreferences
    savedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    //setup the theme
    //int savedThemeId = Integer.parseInt(savedPreferences.getString("pref_key_theme8", "2131361965"));//get the last saved theme id
    //setTheme(savedThemeId);//this refresh the theme if necessary
    // TODO fix the change of status bar

    setContentView(R.layout.activity_main);//load the layout

    // setup the refresh layout
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeRefreshLayout.setColorSchemeResources(R.color.officialBlueFacebook, R.color.darkBlueSlimFacebookTheme);// set the colors
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/* w w  w  .  ja  v a  2 s  .  com*/
        public void onRefresh() {
            refreshPage();//reload the page
            swipeRefresh = true;
        }
    });

    // setup the webView
    webViewFacebook = (WebView) findViewById(R.id.webView);
    setUpWebViewDefaults(webViewFacebook);//set the settings

    goHome();//load homepage

    //WebViewClient that is the client callback.
    webViewFacebook.setWebViewClient(new WebViewClient() {//advanced set up

        // when there isn't a connetion
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            String summary = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><h1 "
                    + "style='text-align:center; padding-top:15%;'>" + getString(R.string.titleNoConnection)
                    + "</h1> <h3 style='text-align:center; padding-top:1%; font-style: italic;'>"
                    + getString(R.string.descriptionNoConnection)
                    + "</h3>  <h5 style='text-align:center; padding-top:80%; opacity: 0.3;'>"
                    + getString(R.string.awards) + "</h5></body></html>";
            webViewFacebook.loadData(summary, "text/html; charset=utf-8", "utf-8");//load a custom html page

            noConnectionError = true;
            swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing
        }

        // when I click in a external link
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url == null || url.contains("facebook.com")) {
                //url is ok
                return false;
            } else {
                if (url.contains("https://scontent")) {
                    //TODO add the possibility to download and share directly

                    Toast.makeText(getApplicationContext(), getString(R.string.downloadOrShareWithBrowser),
                            Toast.LENGTH_LONG).show();
                    //TODO get bitmap from url
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                    return true;
                }

                //if the link doesn't contain 'facebook.com', open it using the browser
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            }
        }

        //START management of loading
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //TODO when I push on messages, open messanger
            //                if(url!=null){
            //                    if (url.contains("soft=messages") || url.contains("facebook.com/messages")) {
            //                        Toast.makeText(getApplicationContext(),"Open Messanger",
            //                                Toast.LENGTH_SHORT).show();
            //                        startActivity(new Intent(getPackageManager().getLaunchIntentForPackage("com.facebook.orca")));//messanger
            //                    }
            //                }

            // show you progress image
            if (!swipeRefresh) {
                final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh);
                refreshItem.setActionView(R.layout.circular_progress_bar);
            }
            swipeRefresh = false;
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // hide your progress image
            final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh);
            refreshItem.setActionView(null);
            super.onPageFinished(view, url);

            swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing
        }
        //END management of loading

    });

    //WebChromeClient for handling all chrome functions.
    webViewFacebook.setWebChromeClient(new WebChromeClient() {
        //to upload files
        //thanks to gauntface
        //https://github.com/GoogleChrome/chromium-webview-samples
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getBaseContext().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                }

                // 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);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

private void getImageIntents() {
    /*/*from   w w  w .j ava  2  s  .  c o m*/
     * if (getIntent().hasExtra("trio")) { _trio = true; _groupId =
     * getIntent().getStringExtra("groupId"); _planner =
     * getIntent().getBooleanExtra("planner", false); } else { _trio =
     * false; _planner = false; _groupId = ""; }
     */
    if (getIntent().getStringExtra("type").equals("gallery")) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        this.startActivityForResult(intent, GALLERY);

        mIsCamera = false;

    } else {
        try {
            startCamera();
            mIsCamera = true;
        } catch (UnsupportedOperationException ex) {
            ex.printStackTrace();
            Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT).show();
        }
    }
    if (getIntent().getBooleanExtra("profile", false) == true) {
        mForProfile = true;
    } else {
        mForProfile = false;
    }
    if (getIntent().getBooleanExtra("createGroup", false) == true) {
        mForGroup = true;
    } else {
        mForGroup = false;
    }
    if (getIntent().getBooleanExtra("groupUpdate", false) == true) {
        mForGroupUpdate = true;
    } else {
        mForGroupUpdate = false;
    }
}

From source file:com.commonsware.android.diceware.PassphraseFragment.java

private void get() {
    Intent i = new Intent().setType("text/plain").setAction(Intent.ACTION_GET_CONTENT)
            .addCategory(Intent.CATEGORY_OPENABLE);

    startActivityForResult(i, REQUEST_GET);
}

From source file:com.money.manager.ex.MainActivity.java

/**
 * pick a file to use//  w  w  w.  j av a2  s.  c  o m
 * 
 * @param file start folder
 */
public void pickFile(File file) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setDataAndType(Uri.fromFile(file), "vnd.android.cursor.dir/*");
    intent.setType("file/*");
    if (((MoneyManagerApplication) getApplication()).isUriAvailable(getApplicationContext(), intent)) {
        try {
            startActivityForResult(intent, REQUEST_PICKFILE_CODE);
        } catch (Exception e) {
            Log.e(LOGCAT, e.getMessage());
            Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        }
    } else {
        Toast.makeText(this, R.string.error_intent_pick_file, Toast.LENGTH_LONG).show();
    }
}

From source file:fileops.FileChooser.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Menu Item Selection Action
    switch (item.getItemId()) {
    case R.id.action_add:
        createFolder();//w ww. j  av  a2s . com
        break;
    case R.id.action_settings:
        Intent i = new Intent(getActivity().getApplicationContext(), Settings.class);
        startActivity(i);
        break;
    case R.id.action_refresh:
        fill(currentDir);
        break;
    case R.id.action_upload:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), 0);
        } catch (android.content.ActivityNotFoundException ex) {
            // Potentially direct the user to the Market with a Dialog
            Toast.makeText(getActivity(), "Please install a File Manager.", 1000).show();
        }
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.lytsing.android.weibo.ui.ComposeActivity.java

@Override
public void onClick(View view) {
    int viewId = view.getId();

    if (viewId == android.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return;/*from ww w .  j  a va2 s  .c om*/
    }

    if (viewId == R.id.ll_text_limit_unit) {
        mContent = mEdit.getText().toString();
        if (TextUtils.isEmpty(mContent))
            return;

        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                mEdit.setText("");
            }
        };

        AlertUtil.showAlert(this, R.string.attention, R.string.delete_all, getString(R.string.ok), listener,
                getString(R.string.cancel), null);
    } else if (viewId == R.id.ib_insert_pic) {
        PopupMenu popup = new PopupMenu(this, view);
        popup.getMenuInflater().inflate(R.menu.pic, popup.getMenu());

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(android.view.MenuItem item) {

                Intent galleryIntent = new Intent();
                galleryIntent.setType("image/*");
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                galleryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                startActivityForResult(galleryIntent, 2);

                return true;
            }
        });

        popup.show();
    } else if (viewId == R.id.ib_face_keyboard) {
        showOrHideIMM();
    } else if (viewId == R.id.ib_insert_location) {
        if (mIsLocation) {
            aq.id(R.id.tv_location).gone();
            aq.id(R.id.ib_insert_location).image(R.drawable.btn_insert_location_nor);
            mIsLocation = false;
            mLatitude = "";
            mLongitude = "";
        } else {
            aq.id(R.id.ly_loadlocation).visible();
            location_ajax();
        }
    }
}