Example usage for android.provider MediaStore EXTRA_OUTPUT

List of usage examples for android.provider MediaStore EXTRA_OUTPUT

Introduction

In this page you can find the example usage for android.provider MediaStore EXTRA_OUTPUT.

Prototype

String EXTRA_OUTPUT

To view the source code for android.provider MediaStore EXTRA_OUTPUT.

Click Source Link

Document

The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.

Usage

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

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

    progressBar = findViewById(R.id.progressBar);

    pm = new PrefManager(MainActivity.this);

    SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE);
    podDomain = config.getString("podDomain", null);

    fab = findViewById(R.id.multiple_actions);
    fab.setVisibility(View.GONE);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*w  w  w .  jav  a  2  s .  c  om*/
    getSupportActionBar().setTitle(null);

    txtTitle = (TextView) findViewById(R.id.toolbar_title);
    txtTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Helpers.isOnline(MainActivity.this)) {
                txtTitle.setText(R.string.jb_stream);
                webView.loadUrl("https://" + podDomain + "/stream");
            } else {
                Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show();
            }
        }
    });

    webView = findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter");

    if (savedInstanceState != null) {
        webView.restoreState(savedInstanceState);
    }

    wSettings = webView.getSettings();
    wSettings.setJavaScriptEnabled(true);
    wSettings.setUseWideViewPort(true);
    wSettings.setLoadWithOverviewMode(true);
    wSettings.setDomStorageEnabled(true);
    wSettings.setMinimumFontSize(pm.getMinimumFontSize());
    wSettings.setLoadsImagesAutomatically(pm.getLoadImages());

    if (android.os.Build.VERSION.SDK_INT >= 21)
        wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    /*
     * WebViewClient
     */
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!url.contains(podDomain)) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
                return true;
            }
            return false;
        }

        public void onPageFinished(WebView view, String url) {
            if (url.contains("/new") || url.contains("/sign_in")) {
                fab.setVisibility(View.GONE);
            } else {
                fab.setVisibility(View.VISIBLE);
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage(description).setPositiveButton("CLOSE", null).show();
        }
    });

    /*
     * WebChromeClient
     */
    webView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView wv, int progress) {
            progressBar.setProgress(progress);

            if (progress > 0 && progress <= 60) {
                Helpers.getNotificationCount(wv);
            }

            if (progress > 60) {
                Helpers.hideTopBar(wv);
                fab.setVisibility(View.VISIBLE);
            }

            if (progress == 100) {
                fab.collapse();
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null)
                mFilePathCallback.onReceiveValue(null);

            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(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
                    Snackbar.make(getWindow().findViewById(R.id.drawer), "Unable to get image",
                            Snackbar.LENGTH_SHORT).show();
                }

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

        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    });

    /*
     * NavigationView
     */
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);

            drawerLayout.closeDrawers();

            switch (menuItem.getItemId()) {
            default:
                Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                        Snackbar.LENGTH_SHORT).show();
                return true;

            case R.id.jb_stream:
                if (Helpers.isOnline(MainActivity.this)) {
                    txtTitle.setText(R.string.jb_stream);
                    webView.loadUrl("https://" + podDomain + "/stream");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_public:
                setTitle(R.string.jb_public);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/public");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_liked:
                txtTitle.setText(R.string.jb_liked);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/liked");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_commented:
                txtTitle.setText(R.string.jb_commented);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/commented");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_contacts:
                txtTitle.setText(R.string.jb_contacts);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/contacts");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_mentions:
                txtTitle.setText(R.string.jb_mentions);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/mentions");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_activities:
                txtTitle.setText(R.string.jb_activities);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/activity");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_followed_tags:
                txtTitle.setText(R.string.jb_followed_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/followed_tags");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_manage_tags:

                txtTitle.setText(R.string.jb_manage_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/tag_followings/manage");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_license:
                txtTitle.setText(R.string.jb_license);
                new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title))
                        .setMessage(getString(R.string.license_text))
                        .setPositiveButton(getString(R.string.license_yes),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        Intent i = new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp"));
                                        startActivity(i);
                                        dialog.cancel();
                                    }
                                })
                        .setNegativeButton(getString(R.string.license_no),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                })
                        .show();

                return true;

            case R.id.jb_aspects:
                txtTitle.setText(R.string.jb_aspects);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/aspects");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_settings:
                txtTitle.setText(R.string.jb_settings);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/user/edit");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();

                    return false;
                }

            case R.id.jb_pod:
                txtTitle.setText(R.string.jb_pod);
                if (Helpers.isOnline(MainActivity.this)) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation))
                            .setMessage(getString(R.string.change_pod_warning))
                            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    webView.clearCache(true);
                                    dialog.cancel();
                                    Intent i = new Intent(MainActivity.this, PodsActivity.class);
                                    startActivity(i);
                                    finish();
                                }
                            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            }).show();
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }
            }
        }
    });

    /*
     * DrawerLayout
     */
    drawerLayout = findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    //calling sync state is necessary or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.loadData("", "text/html", null);
            webView.loadUrl("https://" + podDomain);
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
        }
    }

}

From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java

/**
 * Take a picture with the camera. When an image is captured or the camera
 * view is cancelled, the result is returned in
 * CordovaActivity.onActivityResult, which forwards the result to
 * this.onActivityResult./*from   w ww.j a v a  2s .c  o  m*/
 * 
 * The image can either be returned as a base64 string or a URI that points
 * to the file. To display base64 string in an img tag, set the source to:
 * img.src="data:image/jpeg;base64,"+result; or to display URI in an img tag
 * img.src=result;
 * 
 * @param quality
 *            Compression quality hint (0-100: 0=low quality & high
 *            compression, 100=compress of max quality)
 * @param returnType
 *            Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Display camera
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
    }
    // else
    // LOG.d(LOG_TAG,
    // "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    imageUrls = new ArrayList<String>();
    customProgress = (CustomProgress) findViewById(R.id.pbGoal);
    ivCampaignImage = (ImageView) findViewById(R.id.ivCampaighnImage);
    tvCampaignOverview = (TextView) findViewById(R.id.tvCampaignOverview);
    ivArrowDown = (ImageView) findViewById(R.id.ivArrowDown);
    //   tvCampaignText = (TextView) findViewById(R.id.tvCampaignDetails);
    tvGoal = (TextView) findViewById(R.id.tvCampaignGoal);
    btTakeActionRipple = (RippleView) findViewById(R.id.bt_take_an_action_ripple);
    campaign = (Campaign) getIntent().getSerializableExtra(ITENT_TAG);

    if (campaign.getIsSupported()) {
        btTakeActionRipple.setVisibility(View.GONE);
        ivArrowDown.setImageResource(R.drawable.ic_checked);
    } else {//w ww  .j  a va2  s. co m
        btTakeActionRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                Intent i = new Intent(CampaignDetailActivity.this, SignPetitionActivity.class);
                i.putExtra(ITENT_TAG, campaign);
                startActivity(i);
            }
        });
    }

    getImagesUploadedByUserForCampaign(campaign.getObjectId());

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

    collapsingToolbar.setTitle(campaign.getTitle());
    collapsingToolbar.getCollapsedTitleGravity();
    loadBackdrop(campaign.getImageUrl(), ivCampaignImage);

    PrettyText goal = new PrettyText();
    String decimalGoal = "";
    String decimalCount = "";

    //setting up progress bar
    customProgress.setProgressColor(getResources().getColor(R.color.green_500));
    customProgress.setProgressBackgroundColor(getResources().getColor(R.color.green_200));
    customProgress.setMaximumPercentage(calculatePercentage(campaign.getGoal(), campaign.getGoalCount()));
    customProgress.useRoundedRectangleShape(30.0f);
    customProgress.setShowingPercentage(true);
    //set text above progress
    tvCampaignOverview.setText(campaign.getShortDescription());

    expandableTextView = (ExpandableTextView) findViewById(R.id.viewmore);

    expandableTextView.setText(campaign.getLongDescription());

    //  tvCampaignText.setText(campaign.getLongDescription());

    //set goal text
    decimalGoal = goal.addComma(campaign.getGoal()) + " signatures";
    decimalCount = goal.addComma(campaign.getGoalCount());
    tvGoal.setText(decimalCount + " out of " + decimalGoal);

    ivCampaignImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (imageUrls.size() > 0) {
                Intent i = new Intent(CampaignDetailActivity.this, PhotoGalleryActivity.class);
                i.putExtra(ITENT_TAG, campaign.getObjectId());
                i.putStringArrayListExtra(ITENT_TAG, imageUrls);
                startActivity(i);
                overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            } else {
                buildDialogNoPictures(CampaignDetailActivity.this).show();
            }
        }
    });

    //set floating action button
    floatingCamera = (FloatingActionButton) findViewById(R.id.bt_camera);
    final int[] selection = new int[1];

    floatingCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            FragmentManager fm = getSupportFragmentManager();
            final CameraDialog dialog = CameraDialog.newInstance("Add a new picture:");

            dialog.setOnChoiceClickListener(new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    selection[0] = which;
                }
            });

            dialog.setPositiveListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    if (selection[0] == 0) {
                        // create Intent to take a picture and return control to the calling application
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        photoUri = Uri.fromFile(getOutputMediaFile()); // create a file to save the image
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); // set the image file name
                        // Start the image capture intent to take photo
                        startActivityForResult(intent, TAKE_PHOTO_CODE);
                    } else {
                        // Take the user to the gallery app to pick a photo
                        Intent photoGalleryIntent = new Intent(Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(photoGalleryIntent, PICK_PHOTO_CODE);

                    }
                    dialog.dismiss();

                }
            });

            dialog.setCancelClickListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }

            });

            dialog.show(fm, "TAG_DIALOG");

        }

    });

}

From source file:com.demo.firebase.MainActivity.java

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

    // Check that we have permission to read images from external storage.
    String perm = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    if (!EasyPermissions.hasPermissions(this, perm)) {
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_storage), RC_STORAGE_PERMS, perm);
        return;/*w w  w . j a v  a  2 s.  c o  m*/
    }

    // Choose file storage location, must be listed in res/xml/file_paths.xml
    File dir = new File(Environment.getExternalStorageDirectory() + "/photos");
    File file = new File(dir, UUID.randomUUID().toString() + ".jpg");
    try {
        // Create directory if it does not exist.
        if (!dir.exists()) {
            dir.mkdir();
        }
        boolean created = file.createNewFile();
        Log.d(TAG, "file.createNewFile:" + file.getAbsolutePath() + ":" + created);
    } catch (IOException e) {
        Log.e(TAG, "file.createNewFile" + file.getAbsolutePath() + ":FAILED", e);
    }

    // Create content:// URI for file, required since Android N
    // See: https://developer.android.com/reference/android/support/v4/content/FileProvider.html
    mFileUri = FileProvider.getUriForFile(this, "com.google.firebase.quickstart.firebasestorage.fileprovider",
            file);

    // Create and launch the intent
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);

    // Grant permission to camera (this is required on KitKat and below)
    List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(takePictureIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String packageName = resolveInfo.activityInfo.packageName;
        grantUriPermission(packageName, mFileUri,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    // Start picture-taking intent
    startActivityForResult(takePictureIntent, RC_TAKE_PICTURE);
}

From source file:com.logilite.vision.camera.CameraLauncher.java

/**
 * Take a picture with the camera./*  ww  w.  j ava 2  s. c om*/
 * When an image is captured or the camera view is cancelled, the result is returned
 * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
 *
 * The image can either be returned as a base64 string or a URI that points to the file.
 * To display base64 string in an img tag, set the source to:
 *      img.src="data:image/jpeg;base64,"+result;
 * or to display URI in an img tag
 *      img.src=result;
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param returnType        Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Display camera
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
    }
    //        else
    //            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

From source file:com.zira.registration.DocumentUploadActivity.java

protected void selectImage() {

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

    AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override//from  w ww. java  2  s.c o  m
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                // Ensure that there's a camera activity to handle the intent
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    // Create the File where the photo should go
                    File photoFile = null;
                    try {
                        mCurrentPhotoPath = Util.createImageFile();
                        photoFile = new File(mCurrentPhotoPath);
                    } catch (Exception ex) {
                        // Error occurred while creating the File
                        ex.printStackTrace();
                    }
                    // Continue only if the File was successfully created
                    if (photoFile != null) {
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                        startActivityForResult(takePictureIntent, 1);
                    }
                }
            } else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();

}

From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java

/**
 * Take a picture with the camera./*from w w  w . j a v a  2s .  com*/
 * When an image is captured or the camera view is cancelled, the result is returned
 * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
 *
 * The image can either be returned as a base64 string or a URI that points to the file.
 * To display base64 string in an img tag, set the source to:
 *      img.src="data:image/jpeg;base64,"+result;
 * or to display URI in an img tag
 *      img.src=result;
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param returnType        Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {
    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Display camera
    //        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class);

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
    }
    //        else
    //            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}

From source file:com.hackensack.umc.activity.ProfileSelfiewithCropActivity.java

public Uri dispatchTakePictureIntent(Context context, int cameraFacing, int selectedImageView) {
    Uri imageUri = null;/*from w  w w. java2  s  .  c o  m*/

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    // Intent intent = new Intent(context, PictureDemo.class);
    if (cameraFacing == 1) {
        intent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_FRONT);
    } else {
        intent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_BACK);
    }
    File photo;
    try {
        // place where to store camera taken picture
        photo = CameraFunctionality.createTemporaryFile("picture_" + selectedImageView, ".png");
        // photo.delete();
    } catch (Exception e) {
        Log.v(TAG, "Can't create file to take picture!");
        //Toast.makeText(getActivity(), "Please check SD card! Image shot is impossible!", 10000);
        return imageUri;
    }
    imageUri = Uri.fromFile(photo);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

    //start camera intent
    ((Activity) context).startActivityForResult(intent, Constant.FRAGMENT_CONST_REQUEST_IMAGE_CAPTURE);
    return imageUri;
}

From source file:de.stadtrallye.rallyesoft.model.pictures.PictureManager.java

/**
 * Get an intent to either take a picture with the camera app or select an app that can pick an existing picture
 */// ww w .j  a v  a 2 s  .c  o m
public Intent startPictureTakeOrSelect(SourceHint sourceHint) {
    //Attention: Our RequestCode will not be used for the result, if a jpeg is picked, data.getType will contain image/jpeg, if the picture was just taken with the camera it will be null
    Intent pickIntent = new Intent();
    pickIntent.setType("image/jpeg");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        pickIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        pickIntent.addCategory(Intent.CATEGORY_OPENABLE);
    } else {
        pickIntent.setAction(Intent.ACTION_GET_CONTENT);
    }

    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    Uri fileUri = getPicturePlaceholderUri(PictureManager.MEDIA_TYPE_IMAGE, sourceHint); // reserve a filename to save the image
    takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    takePhotoIntent.putExtra("return-data", true);

    Intent chooserIntent = Intent.createChooser(pickIntent, context.getString(R.string.select_take_picture));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent });

    return chooserIntent;
}

From source file:net.soulwolf.image.picturelib.PictureProcess.java

protected void executeCamera() {
    this.mCameraPath = new File(mCacheDir, String.format("%s%s", Utils.getTempFileName(), TEMP_FILE_SUFFIX));
    if (mCameraPath.exists()) {
        if (!mCameraPath.delete()) {
            TLog.e(LOG_TAG, "CameraPath delete failure!");
        }//from   w  w  w  . jav  a  2s.co  m
    }
    try {
        if (!mCameraPath.createNewFile()) {
            TLog.e(LOG_TAG, "CameraPath create failure!");
        }
    } catch (Exception e) {
        if (mOnPicturePickListener != null) {
            mOnPicturePickListener.onError(new FileCreateException(e));
        }
    }
    Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCameraPath));
    startActivityForResult(intentFromCapture, PictureProcess.CAMERA_REQUEST_CODE);
}