The package The trap.Simplified coding.Firebasstorage;
Import Android.Content.Intent;
Import Android.The graphics.Bitmap;
Import Android.The trap.to hate;
Import Android.the provider.Mediastore;
Import Android.Support.v7.App.AppCompatActivity;
Import Android.The.Bundle;
Import Android.Opinion.Opinion;
Import Android.Widget.switch;
Import Android.Widget.ImageView;
Import Java.I am.IOException;
public class Main activity Is spread AppCompatActivity come into force Opinion.OnClickListener / * Implementation click listener * / {{
// a constant to track the file selector intent
Private Fixed The last int PICK_IMAGE_REQUEST = 234;
//switch
Private switch Click the button;
Private switch Button load;
// image view
Private ImageView imageView;
// a URI object to store the file path
Private to hate file path;
@Override
Protected Zero Go ahead()Bundle saveInstanceState) {{
Super.Go ahead()saveInstanceState);
setContentView()R.Layout.activity_main);
// get ideas from layout
Click the button = ()switch) findViewById()R.Id.Click the button);
Button load = ()switch) findViewById()R.Id.Button load);
imageView = ()ImageView) findViewById()R.Id.imageView);
// Engage audience
Click the button.setOnClickListener()this);
Button load.setOnClickListener()this);
}
// method to show file choice
Private Zero showFileChooser()) {{
Intent is intended = New Intent());
is intended.Settype()“Image / *”);
is intended.Setation()Intent.ACTION_GET_CONTENT);
startActivityForResult()Intent.Crocker()is intended, “Select picture”), PICK_IMAGE_REQUEST);
}
// handling image selector activity result
@Override
Protected Zero onActivityResult()int request code, int results, Intent The data) {{
Super.onActivityResult()request code, results, The data);
If ()request code == PICK_IMAGE_REQUEST && results == RESULT_OK && The data ! = Invalid && The data.get data()) ! = Invalid) {{
file path = The data.get data());
try {{
Bitmap Bitmap = Mediastore.Images.Media.getBitmap()getContentResolver()), file path);
imageView.setImageBitmap()Bitmap);
} Hold ()IOException I) {{
I.Printstacktress());
}
}
}
@Override
public Zero on click()Opinion Opinion) {{
// If the button clicked is to be selected
If ()Opinion == Click the button) {{
showFileChooser());
}
// if clicked button is uploaded
other If ()Opinion == Button load) {{
}
}
}
Source link