0

I wanted to to ask how could i store an image, that will take from gallery and store it to a specific folder. the location i want to store is Shortcut/Images i'm posting my code and i want solution after this how to store this image into the location above (The location is not yet created).. Please keep in mind i want to store image in internal storage so that my app could run in hybrid phone as well

package com.example.mohitgupta.shortcut;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;

public class GetImage extends AppCompatActivity {

    EditText imageName;
    private ImageButton img;
    private String name;
    private Uri selectedImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_image);
        imageName = (EditText) findViewById(R.id.ImageName);
        name = imageName.getText().toString().trim();
    }

    public void GetImageIntent(View view) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(intent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 1 && resultCode == RESULT_OK) {
            selectedImage = data.getData();
            img = (ImageButton) findViewById(R.id.imageSelected);
            img.setImageURI(selectedImage);
        }
    }

    public void SaveButtonClicked(View view){

        BitmapDrawable drawable = (BitmapDrawable) img.getDrawable();
        Bitmap bitmap = drawable.getBitmap();

        //Toast.makeText(GetImage.this,"Image Saved",Toast.LENGTH_SHORT).show();
    }

}

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.mohitgupta.shortcut.GetImage">

    <ImageButton
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_margin="15dp"
        android:layout_gravity="center"
        android:id="@+id/imageSelected"
        android:onClick="GetImageIntent"
        android:scaleType="fitCenter"
        android:backgroundTint="#000000"
        android:src="@drawable/ic_add_a_photo_white_24dp"
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_margin="15dp"
        android:hint="Enter Name of Image"
        android:id="@+id/ImageName"
        android:padding="10dp"
        android:background="@drawable/shapes"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:text="Save"
        android:onClick="SaveButtonClicked"/>
</LinearLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mohit
  • 1
  • 1
  • Please see: [Android saving file to external storage](https://stackoverflow.com/questions/7887078/android-saving-file-to-external-storage) and also: [How to get Bitmap from an Uri?](https://stackoverflow.com/questions/3879992/how-to-get-bitmap-from-an-uri) – Tenten Ponce Jan 03 '18 at 14:08
  • actually as metion above i need to store the image into internal store and the link suggested by u is for external storage. @TentenPonce – Mohit Jan 03 '18 at 17:11
  • can anybody help ????? – Mohit Jan 04 '18 at 02:45
  • Did you try searching? I've found so many links, one them is this: https://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android – Tenten Ponce Jan 04 '18 at 02:48

0 Answers0