new images does not show up after clicking - java

I have my ProfileActivity:
public class ProfileActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
Button gallery = findViewById(R.id.gallery);
gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ProfileActivity.this,GalleryActivity.class);
startActivityForResult(intent, 3);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 3 && resultCode == RESULT_OK && data != null) {
Uri selectedImage = data.getData();
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageURI(selectedImage);
}
}
My GalleryActivity:
public class GalleryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivity(intent);
}
}
my xml file:
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<Button
android:id="#+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10sp"
android:text="Load image from Gallery"
android:textAllCaps="false"
android:textSize="21sp" />
I am facing issue that when user clicked on the new image, it does not show up at the OnActivityResult().
what is the reason and how I can solve it?

After I read and implemented the code in my Android Studio, I was also confused that why did you launch a new Activity (GalleryActivity) to start the image selection. The Intent Intent.ACTION_PICK will show a pick UI.
Obviously, using your code couldn't achieve your goal.
In my opinion, just launch the picking image UI from class GalleryActivity
like this:
gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("TestShowGallery", "TANCOLO===> onClick() ");
// Intent intent = new Intent(TestShowGallery.this,GalleryActivity.class);
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, 3);
}
});
I test my code, it works.
If you really really want to do what you want, there is an approach to achieve your goal, but I don’t recommend you to do that. In order to review how to transfer data between 2 Activities, I show you an example.
You just need to change the code in class GalleryActivity
public class GalleryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("GalleryActivity", "TANCOLO===> onCreate() ");
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, 400);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("GalleryActivity", "TANCOLO===> requestCode = " + requestCode + ", resultCode = " + resultCode);
Log.d("GalleryActivity", "TANCOLO===> data = " + data );
if (requestCode == 400 && resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
finish();
}
}
}

Related

Issue swapping image

I have a ProfileActivity:
public class ProfileActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
final ImageView exampleImage = (ImageView) this.findViewById(R.id.exampleImageView);
exampleImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// [TODO] Implement application behavior when the user clicks the profile picture
//Toast.makeText(ProfileActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
startActivity(new Intent(ProfileActivity.this, GalleryActivity.class));
}
});
}
and I have a second activity called 'GalleryActivity'. the concept is to let the user choose a image from the gallery and then use it to replace the original Profile image.
public class GalleryActivity extends AppCompatActivity {
ImageView imageView;
private static final int PICK_IMAGE = 100;
Uri imageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
imageUri = data.getData();
imageView.setImageURI(imageUri);
}
}
}
however, when I click on a image of the gallery, instead of taking it as new profile image, it take me back to the original image.
what is happening and how I can solve it?
You can use Github Library it will help you.
Here is the Link.
ImagePicker.Companion.with(this)
.crop() //Crop image(Optional), Check Customization for more option
.compress(1024) //Final image size will be less than 1 MB(Optional)
.maxResultSize(1080, 1080)
.start();//Final image resolution will be less than 1080 x 1080(Optional)
On Activity Result.
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
selectedFileURI = data.getData();
if (selectedFileURI != null && !Objects.requireNonNull(selectedFileURI.getPath()).isEmpty()) {
btnUpdate.setVisibility(View.GONE);
civUser.setImageURI(selectedFileURI);
Glide.with(context).load(selectedFileURI).into(civUser);
btnUploadDp.setVisibility(View.VISIBLE);
} else {
Functions.showSnackBar(context, "Cannot Get this Image");
}
}
}
}
Refernce Link.

How to show Image programmatically in custom alert dialog

When you click on button camera should open After capturing the image it should show in customAlertDialog with two options save and cancel
here is my code:
public class MainActivity extends AppCompatActivity{
Button photo;
static final int REQUEST_IMAGE_CAPTURE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
photo = (Button) findViewById(R.id.btn_photo);
photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
}
}
}
Do this call from where you want to call camera::
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 101);
When you come back after capturing picture from camera. It will call "onActivityResult()" and do code like this:
public void onActivityResult(int requestcode,int resultcode,final Intent intent) {
super.onActivityResult(requestcode, resultcode, intent);
if (resultcode == RESULT_OK) {
if (requestcode == 101) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("Save", new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
//Do nothing here. Because image is already saved but if you want to save it other place then do code.
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
//Do here code for for deleting image using uri
}
});
final AlertDialog dialog = builder.create();
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.go_pro_dialog_layout, null);
dialog.setView(dialogLayout);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();
final ImageView image = (ImageView) dialog.findViewById(R.id.goProDialogImage);
Bitmap photo = (Bitmap) intent.getExtras().get("data");
image.setImageBitmap(photo); //Edited here
}
}
}
Now create a XML layout name as "go_pro_dialog_layout.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/goProDialogImage"
android:layout_width="300dp"
android:layout_height="300dp"
/>
</LinearLayout>
And here you are done with whole code..and happy coding.

ImageView and VideoView on same activity

I'm trying to display a captured image on my MainActivity. The problem is it says that onActivityResult is already defined. My first onActivityResult is for the VideoView. Now I have to put a new onActivityResult for my image. How do I make this possible? Do I only have to have one onActivityResult? Do I have to put the second onActivityResult to the first onActivityResult?
Here's my code:
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
Button buttonPlay;
Button buttonFullScreen;
static final int REQUEST_VIDEO_CAPTURE = 1;
VideoView resultvideo;
MediaController mediacontroller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
resultvideo = (VideoView)findViewById(R.id.videoView);
mediacontroller = new MediaController(MainActivity.this);
mediacontroller.setAnchorView(resultvideo);
resultvideo.setMediaController(mediacontroller);
Button click = (Button)findViewById(R.id.buttonRecord);
resultvideo = (VideoView)findViewById(R.id.videoView);
this.imageView = (ImageView)this.findViewById(R.id.imageView);
Button photoButton = (Button) this.findViewById(R.id.buttonCapture);
photoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
public void dispatchTakeVideoIntent(View v) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
final Uri videoUri = data.getData();
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
resultvideo.setVideoURI(videoUri);
mediacontroller.setAnchorView(resultvideo);
resultvideo.pause();
}
buttonPlay = (Button) findViewById(R.id.buttonPlay);
{
buttonPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediacontroller.show();
mediacontroller.setAnchorView(resultvideo);
resultvideo.start();
}
});
}
buttonFullScreen = (Button) findViewById(R.id.buttonFullScreen);
{
buttonFullScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("VIDEO_URI", videoUri.toString());
startActivity(intent);
}
});
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
create two view ImageView for Image and VideoView for Video and use this:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case CAMERA_REQUEST:
if (resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
//Hide video view
videoview.setVisibility(View.GONE);
}
break;
case REQUEST_VIDEO_CAPTURE:
//bring your video stuff here
videoview.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE);
break;
}
}
You need only a single onActivityResult(int requestCode, int resultCode, Intent data) for your Activity class
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case CAMERA_REQUEST:
if (resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
break;
case REQUEST_VIDEO_CAPTURE:
//bring your video stuff here
break;
}
}
Your onActivityResult should look like the above code. Every function can be declared with a the same types and order of parameters only once in a class.
You can not have two function with the same signature.
You have to have a single onActivityResult, and in the if statement, you have to handle the resoult.
Example
if(resultCode == Activity.RESULT_OK){
if (requestCode == CAMERA_REQUEST ) {
...
}
if (requestCode == REQUEST_VIDEO_CAPTURE ) {
...
}
}

How to set Bitmap ImageView in MainActivity from result Crop Activity?

Hello I use this https://github.com/chemalarrea/CropImage to crop Photo from camera. But there not set result to ImageView, so
I modified main.xml like here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/hello" />
<Button android:id="#+id/button" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Take picture" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mImageView" />
</LinearLayout>
this is MainActivity.class
public class MainActivity extends Activity {
private static final int PICK_FROM_CAMERA = 1;
private Uri mImageCaptureUri;
private ImageView mImageView;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
doTakePhotoAction();
}
});
mImageView = (ImageView) findViewById(R.id.mImageView);
}
private void doTakePhotoAction() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"tmp_contact_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
try {
intent.putExtra("return-data", false);
startActivityForResult(intent, PICK_FROM_CAMERA);
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case PICK_FROM_CAMERA:
Intent intent = new Intent(this, CropImage.class);
intent.putExtra("image-path", mImageCaptureUri.getPath());
intent.putExtra("scale", true);
startActivity(intent);
break;
}
}
}
so How to set Bitmap ImageView in MainActivity from result Crop Activity ?
From looking the code here:
https://github.com/chemalarrea/CropImage/blob/master/src/com/droid4you/util/cropimage/CropImage.java
Do something along the lines of this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case PICK_FROM_CAMERA:
if (data != null && "inline-data".equals(data.getAction())) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.getParcelable("data");
mImageView.setImageBitmap(imageBitmap);
}
else {
Intent intent = new Intent(this, CropImage.class);
intent.putExtra("image-path", mImageCaptureUri.getPath());
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);
}
break;
}
}
Try this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == PICK_FROM_CAMERA ) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.getParcelable("data");
mImageView.setImageBitmap(imageBitmap);
}
}

No Apps Can Perform This Action - Opening Image

I'm attempting to view an image after selecting it using Gallery launched via intent however I'm getting an error when attempting to do so. I think this may have to do with:
intent.setDataAndType(selectedVideo, "video/*, image/*");
or some sort of conflict in onActivityResult between opening images and video - but I'm not sure.
Any input is greatly appreciated:
P.S.
Ideally this would open the image using the gallery once it is selected - not open it using my app.
Source:
ImageButton pb = (ImageButton) findViewById(R.id.photos);
pb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Toast.makeText(UI.this, "Before and After Photos",
// Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PHOTO);
}
});
ImageButton vb = (ImageButton) findViewById(R.id.video);
vb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Toast.makeText(UI.this, "Video Testimonial", Toast.LENGTH_LONG)
// .show();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("video/*");
startActivityForResult(intent, SELECT_VIDEO);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == Activity.RESULT_OK) {
Uri selectedVideo = data.getData();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*, image/*");
startActivity(Intent.createChooser(intent,
"Complete action using"));
}
}
;
}
}
Edit:
I'm trying to accomplish a very simple task:
I need to be able to click the imageButton for video, select from gallery and play, and click the imageButton for images, select an image and view it - ALL USING THE GALLERY
How might this be accomplished?
Current Source:
ImageButton pb = (ImageButton) findViewById(R.id.photos);
pb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PHOTO);
}
});
ImageButton vb = (ImageButton) findViewById(R.id.video);
vb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
.show();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("video/*");
startActivityForResult(intent, SELECT_VIDEO);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == Activity.RESULT_OK) {
Uri selectedVideo = data.getData();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*, image/*");
startActivity(Intent.createChooser(intent,
"Complete action using"));
}
}
;
}
}
What you have
startActivityForResult(intent, SELECT_PHOTO);
Then you have
if (requestCode == 1) {
Then
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*, image/*");
startActivity(Intent.createChooser(intent,
"Complete action using"));
You are trying to use intent chooser and android says there is no app that can perform the action.
You need to change to
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PHOTO) {
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
iv.setImageURI(selectedImage);
}
}
Example:
I have used a ImageView to display the image selected from gallery
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton1"
android:layout_centerHorizontal="true"
android:layout_marginTop="168dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
MainActivity
public class MainActivity extends Activity {
private static final int SELECT_PHOTO = 100;
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv= (ImageView) findViewById(R.id.imageView1);
ImageButton ab = (ImageButton) findViewById(R.id.imageButton1);
ab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Image Testimonial", Toast.LENGTH_LONG)
.show();
Intent intent = new Intent(
Intent.ACTION_PICK
);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PHOTO);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PHOTO) {
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
iv.setImageURI(selectedImage);
}
}
}
}
To the edited question
public class MainActivity extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 5000;
private static final int SELECT_PHOTO = 101;
private static final int SELECT_VIDEO = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fg);
ImageButton ab = (ImageButton) findViewById(R.id.imageButton1);
ab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Audio Testimonial", Toast.LENGTH_LONG)
.show();
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 1);
}
});
ImageButton vb = (ImageButton) findViewById(R.id.imageButton2);
vb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Video Testimonial", Toast.LENGTH_LONG)
.show();
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("video/*");
startActivityForResult(photoPickerIntent, SELECT_VIDEO);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
if (requestCode == SELECT_VIDEO) {
{
Uri selectedVideo = data.getData();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*");
startActivity(intent);
}
}
else if (requestCode == SELECT_PHOTO) {
Uri selectedImage = data.getData();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(selectedImage,"image/*");
startActivity(intent);
}
}
// ImageButton wb = (ImageButton) findViewById(R.id.imageButton3);
// wb.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v) {
// Toast.makeText(MainActivity.this, "Written Testimonial",
// Toast.LENGTH_LONG).show();
// Intent intent = new Intent(MainActivity.this, Written.class);
// startActivity(intent);
// }
// });
ImageButton pb = (ImageButton) findViewById(R.id.imageButton4);
pb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Before and After Photos",
Toast.LENGTH_LONG).show();
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});
}
}
In Huawei P9, android marshmallow, one device has not any application that can manage that intent's request (it has no gallery nor photo app). So manually installed those app and worked perfectlly

Categories

Resources