I am working on an app which let users choose photo from their gallery. The problem is I need to show the gallery in landscape only. Is it possible to do it?
I use this code:
Intent galleryIntent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RQC_GALLERY);
When you start any activity using explicit intent, you loose control from your application. Android finds out and application to perform that is described in intent object.
Intent object attributes details
From no where you can have control on next application regarding view.
If you want to fulfill specific requirement than make your own activity with Grid view and use image adapter to set images.
Here is one link which shows how to set images in adapter. It will help to design your code if necessary.
Related
I want to share a text using this:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
As you can see in the below picture, I know how to acheive a dialog which lets user picks his choice (My app). But recently I saw an app which is letting users pick their choice within its activity (Desired).
Any idea how to acheive desired one? Thank you all.
This is the code, I've been using for sharing 'Referral Code' from within my app:
ShareCompat.IntentBuilder
.from(this) // getActivity() or activity field if within Fragment
.setText("message") // This will be populated as user's message
.setType("text/plain") // most general text sharing MIME type
.setChooserTitle("Share code using:")
.startChooser();
It opens up a view similar to your right image.
Create Custom layout. (Right image)
Embed in BottomSheetLayout
Use setState() to show your "Share Screen"
................................................
or You can just do the same inside an AlertDialog. (Left Image)
You can query for the list of apps that are registered to handle the action and then display the result in the way that you like the most. When the user will choose something you can start the selected activity.
I just need to put a camera inside one of the three fragments of my main activity, like ([f]-[f]-[C]), where () is my main activity, [] is a fragment, C is the camera and f are just a fragment (they are full screen swipable). I need to create a whole camera (coding , etc) just for it or it is possible to call android native camera app with intent to an fagment?
I need to create a whole camera (coding , etc) just for it
Yes, whether you write it yourself or use one from a library.
or it is possible to call android native camera app with intent to an fagment?
No, you cannot embed a third-party app in a fragment of your app.
If you need to take a picture, you can just use an intent to launch the system camera app. Doing so will make it a lot easier to code, but you won't be able to show a live preview, as you're actually handling control to the camera app through that intent.
Manually handling the entire camera lifecycle allows you to have control over the preview and show it real-time in your app. Also, if you need to have the live preview in your app, this is the way to go and can't be accomplished using just an Intent.
You might find the UltimateAndroidCameraGuide on GitHub very helpful for your problem, particularly the SimpleCameraIntentFragment and the NativeCameraFragment files in that repo.
You can use an Intent to launch the camara and it will launch the camara default app., just be careful to detect when your "C" fragment is displayed, here: How to determine when Fragment becomes visible in ViewPager
If you dont do that, android pre-caches fragment before showing it and your intent will fire.
On your activity use:
#Override public void onResume() {
super.onResume();
if(viewPager.getCurrentItem() == 2){
//Your code here. Executed when fragment is seen by user.
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
See for camera launch with intent options: http://developer.android.com/guide/topics/media/camera.html#intent-image
In my android app, I create an intent to display an image in the photogallery app.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file:///storage/sdcard0/arin/category/1/1.png"), "image/*");
context.startActivity(intent);
This opens the photo app and shows that image but only that image...
I know there are other images in the same folder. But the app wont let swipe left/right and switch images. How can I change the code so it will let me see the other pics in the same folder...
Thanks
How can I change the code so it will let me see the other pics in the same folder
Write your own "photogallery" code.
There are hundreds, perhaps thousands, of apps that are capable of responding to your Intent. None of them have to offer any means to "swipe left/right and switch images". If you want a specific set of behaviors, write them yourself. If you want the user to be able to view the image in the user's chosen app, then stick with your existing code and do not worry about the behavior of the user's chosen app.
I got a problem similar to (How to take multiple photos before dismissing camera intent?)!
how ever he used the:
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
I need to use somewhat like this:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
for(int i=0;i<2;i++){
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
since i need to take exactly 2 photos, preview it with the default check or x of using MediaStore.ACTION_IMAGE_CAPTURE(to remove the hassle of displaying it to an imageview, go back again to capture)
then only go back to the main activity, knowing the data that i had taken 2 photos/saved it.
however, when i used that for loop, it returned only the last image taken, and it resized 2 times( i have a code that resizes 25% of the original captured photo, so after the code executed, it resized to 6.25% of original(1/4 of 25%) before it returns to the main activity).
Can someone give me light what is happening and give me a solution? Thanks a lot in advance! :D
As much as possible, i want to use the built in camera app, since it has a lot of other functions readily available compared to having the hassle of building your own custom camera. Btw im using android jellybean. 4.1.1
Call your second startActivityForResult() from the onActivityResult() you get from your first startActivityForResult(). Bear in mind that startActivityForResult() is asynchronous -- the other activity is not started right away.
I have an app which wants to view an image in the gallery app.
I use this code to view it:
File cachedImage = cache.getFile(image.getImageUrl());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cachedImage), "image/*");
startActivity(intent);
This works except when I click the edit setting here:
and I get the no apps can perform this action message:
Is there some way to make this work? Do I need to pass additional extras? I know the Gmail app is able to view an image attachment in the gallery and the edit function works. This is on JellyBean.
Is there some way to make this work?
Install an app that can edit pictures. Your screenshots appear to be of the Gallery app, which is presumably trying to use ACTION_EDIT to start an activity to edit the picture, and there is no such activity available.