Android Intent setSelector - android

Why when I use setSelector method it returns neither Camera activities nor Gallery Activities.I have the following code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent camera= new Intent("android.media.action.IMAGE_CAPTURE");
Intent gallery = new Intent();
gallery.setAction(android.content.Intent.ACTION_VIEW);
gallery.setType("image/*");
gallery.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
camera.setSelector(gallery);
startActivity(camera);
}
According to Android's reference API "If the selector is set, it will be used when trying to find entities that can handle the Intent, instead of the main contents of the Intent."
I thought that I will get a dialog that opens the gallery instead of camera. But, instead of these I got a dialog that returns arbitrary applications/activities, such as Call Settings, Network Settings, SIM Toolkit, etc.
When I remove the camera.setSelector(gallery); method everything works like a charm, but when I use camera.setSelector(gallery); method it returns neither Camera activities nor Gallery Activities.
Could somebody explain me why I got a dialog with these arbitrary activities instead of appropriate?
I don't want to remove the camera.setSelector(gallery); because I am trying to understand how it works!

use this intent to open your gallery
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
then use startActivityForResult to get the selected photo from gallery. hope this helps

Replace this code :
Intent camera= new Intent("android.media.action.IMAGE_CAPTURE");
With this :
Intent camera= new Intent(Intent.ACTION_VIEW,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

Related

Reading gallery folders using Implicit intent

I am implementing an android app, which will synchronize images from selected folder to server (as Google Photo). I want that user will select folder by clicking on button. I can achieve this by creating my own view. But, if implicit intent can any implicit intent action by which I can show user only images folder from device?
Try,
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 100);
change EXTERNAL_CONTENT_URI constant accordingly.

startActivityForResult - put Value to onActivityResult

I'm starting an Intent for choosing an Image from Gallery. My target is to put an Extra (an int value) to onActivityResult, but I can figure out how to do this.
The way I call the image chooser:
Intent photoPickerIntent = new Intent();
photoPickerIntent.setType("image/jpg");
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent photoResultIntent = Intent.createChooser(photoPickerIntent, "Bild auswählen");
fragment.startActivityForResult(photoResultIntent, HorseFragment.PICK_IMAGE, bundle);
What I tried (with no success):
instantiating a new Bundle and give it to startActivityForResult() as third parameter
using photoResultIntent.putExtra...
How can I put a value to my target activity and retrieve it in onActivityResult? Can anyone explain it to me?
Thank you a lot for your time and your help!

Adding Camera to a tab in android

I want to add camera to a tab in a way that once i click that tab, the camera will work immediately.
I tried to use similar way to buttons by setting onClickListener but it seems tabs differs from buttons when it comes to listeners.
-May be this would help you.
-onselecting the tab you want to launch camera.. call intent class like this..
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity) con).startActivityForResult(cameraIntent,
CAMERA_REQUEST_CODE);
`
-Onactivity result method of new tabhost call your desired code further...
-THanks!

Open camera app with a thunbnail icon

I want to launch Android built-in camera app with a thumbnail icon on the right-bottom. Here is my code to open the camera app.
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I think I need to put a intent data to do it. I look forward to your help.
Thanks.
Just create an image button, or button or anything you desire really.
In the onclick event add something like:
String saveFileName= Environment.getExternalStorageDirectory() + "/test.png";
// BUILT IN CAMERA
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(saveFileName) );
this.startActivityForResult(camera, 1);
Make sure you have necessary permissions set. Like saving to the SDCard.
You are very close, you dont need those flags set. And you should ideally specify where you are saving the image.
If you are wondering how to make the button take a look here

how to override onBackPressed of a camera activity? i.e android.provider.MediaStore.ACTION_IMAGE_CAPTURE

is there any way to override the onBAckPressed() for camera activity i.e android.provider.MediaStore.ACTION_IMAGE_CAPTURE.
Let me explain what I m trying to do
I have a button when user clicks that a dialog appears which asks the user to either select picture from gallery or capture image using camera.
so the code is like this
case R.id.btn_live:
Intent liveIntent= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(liveIntent,RESULT_CAPTURE_IMAGE);
myDialog.dismiss();
break;
case R.id.btn_gallery:
Intent galIntent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galIntent, RESULT_LOAD_IMAGE);
myDialog.dismiss();
break;
now suppose user selects any of the two actions then we start that using intent
like this -
Intent liveIntent= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
The user enters into an the camera activity , now when the user is using camera , i want to apply some functionality if he presses back button.
so how will i do it?
any thoughts?
you cant override methods in external activities you are calling. However, when a user hits back in an activity that was called using startActivityForResult the response code RESULT_CANCELLED is generally returned (there may be instances where this isn't true). In your onActivityResult method simply check for the RESULT_CANCELLED code and call whatever functionality you need

Categories

Resources