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.harmazing.aixiumama.activity.ActivityGallery.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);
    CuteApplication.activityList.add(this);

    mGPUImage = new GPUImage(getApplication());
    relativeLayout = (RelativeLayout) findViewById(R.id.top_view);
    frame = (FrameLayout) findViewById(R.id.frame);
    sticker = (HSuperImageView) findViewById(R.id.sticker);
    // ?//from w  w  w.  j  ava 2  s  . c o m
    //        sticker.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, CuteApplication.getScreenHW(getApplicationContext())[0]));
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(sticker.getLayoutParams());
    margin = CuteApplication.getScreenHW(getApplicationContext())[0] / 2
            - CuteApplication.getWidth(sticker) / 2;
    params.setMargins(margin / 2 - 2, margin / 2 - 2, 0, 0);
    sticker.setLayoutParams(params);

    sticker.setOnDeleteListener(new HSuperImageView.OnDeleteListener() {
        @Override
        public void onDelete() {
            AlertDialog builder = new AlertDialog.Builder(ActivityGallery.this)
                    .setMessage("???")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            sticker.setVisibility(View.GONE);
                            stickerID = 0;
                        }
                    }).setNegativeButton("?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create();
            builder.show();
        }
    });

    viewpager = (NoTouchViewPager) findViewById(R.id.viewpager);

    viewpager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            return true;
        }
    });

    beautifyBtn = (Button) findViewById(R.id.beautify_btn);
    beautifyBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            viewpager.setCurrentItem(0);
            paperBtn.setTextColor(getResources().getColor(R.color.white));
            beautifyBtn.setTextColor(getResources().getColor(R.color.pink));
        }
    });

    paperBtn = (Button) findViewById(R.id.paper_btn);
    paperBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            viewpager.setCurrentItem(1);
            paperBtn.setTextColor(getResources().getColor(R.color.pink));
            beautifyBtn.setTextColor(getResources().getColor(R.color.white));
        }
    });

    findViewById(R.id.back).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            AlertDialog builder = new AlertDialog.Builder(ActivityGallery.this)
                    .setMessage("?")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    }).setNegativeButton("?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create();
            builder.show();
        }
    });

    /*
    
     */
    findViewById(R.id.next).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Intent intent = new Intent(ActivityGallery.this, AddLabelActivity.class);
            if (sticker != null) {
                sticker.clearBorder(true);
            }

            //  ??mGPUImage.
            //                    CuteApplication.setFilterCLear(mGPUImage);
            //                    mGPUImage.setImage(GetandSaveCurrentImage());

            //                    Bitmap mBitamp = GetandSaveCurrentImage();
            //                    byte[] bytes = BitmapUtil.bitmap2ByteArray(mBitamp);

            bitmap = GetandSaveCurrentImage();
            LogUtil.v("activityGallery" + "stickerID", stickerID);
            if (stickerID != 0)
                intent.putExtra("stickerID", stickerID);
            //              intent.putExtra("bitmap_byte", bytes);
            startActivity(intent);
            stickerID = 0;
        }
    });

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

    //     Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    if (getIntent().getIntExtra("action", 10) == TabHostActivity.PHOTO) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, REQUEST_PICK_IMAGE);
    } else if (getIntent().getIntExtra("action", 10) == TabHostActivity.CAMERA) {
        takePhoto();
    }
}

From source file:com.example.evan.comp296.profile.MainActivity_Profile.java

private void launchCamera() {
    Log.d(TAG, "launchCamera");

    // Pick an image from storage
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent, RC_TAKE_PICTURE);
}

From source file:com.example.android.notepad.NotesList.java

@Override
protected void onListItemClick(ListView 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)) {
        // The caller is waiting for us to return a note selected by
        // the user.  The have clicked on one, so return it now.
        setResult(RESULT_OK, new Intent().setData(uri));
    } else {/*from w w w  .  j av  a2s. co m*/
        // Launch activity to view/edit the currently selected item
        startActivity(new Intent(Intent.ACTION_EDIT, uri));
    }
}

From source file:com.psu.capstonew17.pdxaslapp.CreateCardActivity.java

private void dispatchGalleryIntent() {
    Intent intent = new Intent();
    intent.setType("video/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, SELECT_VIDEO), GET_VIDEO);
}

From source file:com.keepassdroid.fileselect.FileSelectActivity.java

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

    fileHistory = App.getFileHistory();//from   w  w w.  j  a  va  2 s .  c  om

    if (fileHistory.hasRecentFiles()) {
        recentMode = true;
        setContentView(R.layout.file_selection);
    } else {
        setContentView(R.layout.file_selection_no_recent);
    }

    mList = (ListView) findViewById(R.id.file_list);

    mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            onListItemClick((ListView) parent, v, position, id);
        }
    });

    // Open button
    Button openButton = (Button) findViewById(R.id.open);
    openButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String fileName = Util.getEditText(FileSelectActivity.this, R.id.file_filename);

            try {
                PasswordActivity.Launch(FileSelectActivity.this, fileName);
            } catch (ContentFileNotFoundException e) {
                Toast.makeText(FileSelectActivity.this, R.string.file_not_found_content, Toast.LENGTH_LONG)
                        .show();
            } catch (FileNotFoundException e) {
                Toast.makeText(FileSelectActivity.this, R.string.FileNotFound, Toast.LENGTH_LONG).show();
            }

        }
    });

    // Create button
    Button createButton = (Button) findViewById(R.id.create);
    createButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String filename = Util.getEditText(FileSelectActivity.this, R.id.file_filename);

            // Make sure file name exists
            if (filename.length() == 0) {
                Toast.makeText(FileSelectActivity.this, R.string.error_filename_required, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            // Try to create the file
            File file = new File(filename);
            try {
                if (file.exists()) {
                    Toast.makeText(FileSelectActivity.this, R.string.error_database_exists, Toast.LENGTH_LONG)
                            .show();
                    return;
                }
                File parent = file.getParentFile();

                if (parent == null || (parent.exists() && !parent.isDirectory())) {
                    Toast.makeText(FileSelectActivity.this, R.string.error_invalid_path, Toast.LENGTH_LONG)
                            .show();
                    return;
                }

                if (!parent.exists()) {
                    // Create parent dircetory
                    if (!parent.mkdirs()) {
                        Toast.makeText(FileSelectActivity.this, R.string.error_could_not_create_parent,
                                Toast.LENGTH_LONG).show();
                        return;

                    }
                }

                file.createNewFile();
            } catch (IOException e) {
                Toast.makeText(FileSelectActivity.this,
                        getText(R.string.error_file_not_create) + " " + e.getLocalizedMessage(),
                        Toast.LENGTH_LONG).show();
                return;
            }

            // Prep an object to collect a password once the database has
            // been created
            CollectPassword password = new CollectPassword(new LaunchGroupActivity(filename));

            // Create the new database
            CreateDB create = new CreateDB(FileSelectActivity.this, filename, password, true);
            ProgressTask createTask = new ProgressTask(FileSelectActivity.this, create,
                    R.string.progress_create);
            createTask.run();

        }

    });

    ImageButton browseButton = (ImageButton) findViewById(R.id.browse_button);
    browseButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (StorageAF.useStorageFramework(FileSelectActivity.this)) {
                Intent i = new Intent(StorageAF.ACTION_OPEN_DOCUMENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                        | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
                startActivityForResult(i, OPEN_DOC);
            } else {
                Intent i;
                i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");

                try {
                    startActivityForResult(i, GET_CONTENT);
                } catch (ActivityNotFoundException e) {
                    lookForOpenIntentsFilePicker();
                } catch (SecurityException e) {
                    lookForOpenIntentsFilePicker();
                }
            }
        }

        private void lookForOpenIntentsFilePicker() {

            if (Interaction.isIntentAvailable(FileSelectActivity.this, Intents.OPEN_INTENTS_FILE_BROWSE)) {
                Intent i = new Intent(Intents.OPEN_INTENTS_FILE_BROWSE);
                i.setData(Uri.parse("file://" + Util.getEditText(FileSelectActivity.this, R.id.file_filename)));
                try {
                    startActivityForResult(i, FILE_BROWSE);
                } catch (ActivityNotFoundException e) {
                    showBrowserDialog();
                }

            } else {
                showBrowserDialog();
            }
        }

        private void showBrowserDialog() {
            BrowserDialog diag = new BrowserDialog(FileSelectActivity.this);
            diag.show();
        }
    });

    fillData();

    registerForContextMenu(mList);

    // Load default database
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String fileName = prefs.getString(PasswordActivity.KEY_DEFAULT_FILENAME, "");

    if (fileName.length() > 0) {
        Uri dbUri = UriUtil.parseDefaultFile(fileName);
        String scheme = dbUri.getScheme();

        if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) {
            String path = dbUri.getPath();
            File db = new File(path);

            if (db.exists()) {
                try {
                    PasswordActivity.Launch(FileSelectActivity.this, path);
                } catch (Exception e) {
                    // Ignore exception
                }
            }
        } else {
            try {
                PasswordActivity.Launch(FileSelectActivity.this, dbUri.toString());
            } catch (Exception e) {
                // Ignore exception
            }
        }
    }
}

From source file:com.business.rushour.businessapp.RiderMainActivity.java

private void captureImage() {

    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(RiderMainActivity.this);
    builder.setTitle("Add Photo!");

    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override/*from w  w  w.ja v a2  s.c  o  m*/
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                try {

                    final Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    //startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

                    // start the image capture Intent
                    startActivityForResult(cameraIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
                }

                catch (ActivityNotFoundException anfe) {
                    String errorMessage = "Whoops - your device doesn't support capturing images!";
                    Toast toast = Toast.makeText(RiderMainActivity.this, errorMessage, Toast.LENGTH_SHORT);
                    toast.show();
                }
            }

            else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                startActivityForResult(intent, PICK_IMAGE_REQUEST);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

From source file:com.mendhak.gpslogger.common.PrefsIO.java

private void BrowseFile() {
    Intent chooseFile;//from www  . j  av a  2  s.  c o  m
    Intent intent;
    chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
    chooseFile.setType("file/*");
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(chooseFile, 0);
    if (list.size() > 0) {
        intent = Intent.createChooser(chooseFile, context.getString(R.string.ChooseFile));
        Utilities.LogDebug("Trying to start file browser...");
        ((Activity) context).startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
    } else
        Toast.makeText(context, context.getString(R.string.NoFSBrowser), Toast.LENGTH_SHORT).show();
}

From source file:de.petermoesenthin.alarming.fragments.SoundManagerFragment.java

/**
 * Start an intent to load an audio file
 *//*from w  w w  .  ja v a  2 s  .c o m*/
private void startAudioFileIntent() {
    Log.d(DEBUG_TAG, "Starting file intent");
    Intent audioIntent = new Intent();
    //select files
    //audioIntent.setType("file/*");

    //select audio files
    audioIntent.setType("audio/*");

    audioIntent.setAction(Intent.ACTION_GET_CONTENT);
    try {
        startActivityForResult(audioIntent, 1);
    } catch (ActivityNotFoundException e) {
        Log.e(DEBUG_TAG, "No activity for file intents available", e);
    }
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

public void getImage() {
    Intent intent = new Intent();
    String title = GET_PICTURE;/*from w ww.j a  v a 2s .  c o  m*/
    if (mMediaType == PICTURE) {
        intent.setType("image/*");
    } else if (mMediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (mMediaType == ALLMEDIA) {
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // ??
    mExtensionContext.getSystemContext().startActivityForResult(this,
            Intent.createChooser(intent, new String(title)), PHOTO_REQUEST_CODE);
}

From source file:com.sxt.chat.activity.NotifycationActivity.java

private void startGalleryApp() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        intent.setAction(Intent.ACTION_GET_CONTENT);
    } else {//from w ww .  j a  v  a2 s  .  co  m
        intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
    }

    intent = Intent.createChooser(intent, "");
    startActivityForResult(intent, REQUEST_CODE_GALLERY);
}