I have been trying to integrate the Adobe Creative SDK in my app. I have added one extra activity which launches camera and gallery and saves the image in an ImageView.
I successfully passed the image to another activity but for using the Adobe Creative SDK you need an uri path.
After providing the uri path I am getting an error -
'AdobeImageIntent()' has private access in 'com.adobe.creativesdk.aviary.AdobeImageIntent'
here is the onCreate method -
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imageBitmap");
String path = bmp.toString();
Uri imageUri = Uri.parse(path);
Intent imageEditorIntent = new AdobeImageIntent().Builder(this)
.setData(imageUri)
.withOutput(Uri.parse("file://" + getFilesDir() + "my-pic-name.jpg")) // output file destination
.withOutputFormaat(Bitmap.CompressFormat.JPEG)
.withOutputSize(MegaPixels.Mp5)
.withOutputQuality(90)
.build();
startActivityForResult(imageEditorIntent,1);
Intent cdsIntent = AdobeImageIntent.createCdsInitIntent(getBaseContext(),"CDS");
startService(cdsIntent);
imageView = (ImageView) findViewById(R.id.imageView);
}
why I am getting this error?
Thanks for help!
Hope I would get answers!!
Replace
Intent imageEditorIntent = new AdobeImageIntent().Builder(this)
^^^^^
with:
Intent imageEditorIntent = new AdobeImageIntent.Builder(this)
^^^^^
Possible issues with the code above
Try removing the cdsIntent and see if your code runs.
Without more information, it's hard to know, but it could be that both your cdsIntent and your imageView assignments are coming too late in onCreate().
Taking a photo from your app
You can create a new camera Intent and start it like this:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(cameraIntent, 400); // Can be any int
}
The results from the camera will come back to you in onActivityResult().
Handling the results from the camera Intent
How to handle the results will depend on what your app does. Google has a nice overview on the subject on the Android Developer Portal.
If you have further questions beyond the scope of this one, it may be good to make a new question to help get this one more focused.
Related
Is there has a way to know which app(packageName or label) user use to capture,when I call capture intent
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE)
for example: com.google.camera
Photos taken by the ACTION_IMAGE_CAPTURE are not registered in the MediaStore automatically on all devices.
The official Android guide gives that example: http://developer.android.com/guide/topics/media/camera.html#intent-receive But that does not work either on all devices.
The only reliable method I am aware of consists in saving the path to the picture in a local variable. Beware that your app may get killed while in background (while the camera app is running), so you must save the path during onSaveInstanceState.
Edit after comment:
Create a temporary file name where the photo will be stored when starting the intent.
File tempFile = File.createTempFile("my_app", ".jpg");
fileName = tempFile.getAbsolutePath();
Uri uri = Uri.fromFile(tempFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, PICTURE_REQUEST_CODE);
fileName is a String, a field of your activity. You must save it that way:
#Override
public void onSaveInstanceState(Bundle bundle)
{
super.onSaveInstanceState(bundle);
bundle.putString("fileName", fileName);
}
and recover it in onCreate():
public void onCreate(Bundle savedInstanceState)
{
if (savedInstanceState != null)
fileName = savedInstanceState.getString("fileName");
// ...
}
Here it is
Intent intent = getPackageManager().getLaunchIntentForPackage("package name") // package name, e.g : com.google.camera
startActivity(intent)
You can open another application this way
You can obtain the answer only if there are 1 such app or the user selected the default app for this intent.
For obtain list of apps which support this intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0);
So if this list contains only 1 app then you will have the required ResolveInfo.
For obtain app which was selected as default by the user:
ResolveInfo defaultInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
This can be null if nothing selected.
If you have ResolveInfo then you can obtain the packageName and app name:
String packageName = resolveInfo.activityInfo.packageName;
String appName = resolveInfo.loadLabel(getPackageManager()).toString();
There's lots of questions on the same topic, however none of them provided me an answer.
I've tried a lot of solutions, yet none of them is working for me so far.
I'm invoking the camera intent in a fragment and inserting uri to the newly created file where I want the picture to be stored and then on activityresult I'm passing the uri to a new activity where I want to show it in an imageview and then proceed to upload it.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File mImageFile = new File(Environment.getExternalStorageDirectory().getPath()+"/DCIM/" + "Camera/" + File.separator+System.currentTimeMillis()+".jpg");
imageUri = Uri.fromFile(mImageFile);
Log.d("camera", "imageUri: " + imageUri.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent, CAMERACODE);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case CAMERACODE:{
if (resultCode == Activity.RESULT_OK) {
Intent intent = new Intent(getActivity(), SubmitActivity.class);
intent.putExtra("imageuri", imageUri.toString());
getActivity().startActivity(intent);
and in SubmitActivity:
Bundle extras = getIntent().getExtras();
imageUri = extras.getString("imageuri"); <-- imageUri has the correct path, and the actual file is created and the photo is there. The photo is not showing up on gallery for some reason though, only when browsing the folders. What is the reason for this?
iv = (ImageView) findViewById(R.id.selectedpicture);
iv.setImageURI(Uri.parse(imageUri)); <-- this line causes a NullPointerException.
Can anyone explain the reason for why the setImageURI fails? Any alternative way of doing this? I'm using Samsung Galaxy S3
I believe iv is null and there is no problem with imageuri.
Check whether you have done setContentView and check if the layout has selectedpicture imageView.
Edit:
The photo is not showing up on gallery for some reason though
Gallery uses MediaStore to get all the photos on the sdcard. But when you take a picture MediaStore db would not have been updated. For the pic to show up in gallery MediaScanning should be run. Check this post
I am trying to programatically launch or open the photo gallery after passing a photo name search parameter.
I am new at this. I am thinking maybe intents can be used but not sure so I am wondering if anyone could please point me in the right direction. Preferably with some code examples.
Much thanks.
RE-EDIT
As requested, this is the code I have so far..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// CAMERA_PIC_REQUEST = 2600;
cameraIntent = Intent.createChooser(intent,"Select Picture");
you can try follow code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(photoUri);
context.startActivity(intent);
I think this is what you mean, correct me if I'm wrong:
String nameOfPhotoToBeRetrieved = "myPhoto";
String WHERE = "TITLE ="+nameOfPhotoToBeRetrieved;
Then you can use the following line to deliver a result to your cursor/listener:
CursorLoader(context,content_uri,null,WHERE,null,null).deliverResult(myCursor);
I want to start camera activity in my android app and I know how to do that. I want to ask when the camera activity finishes, how can I check as if it was the picture or the video taken by the user?
UPDATED
I have a dialog where it asks 2 things.
New Photo or Video
Existing Photo or Video
If it's no. 1, it means camera will be started and user can either take a picture or the video and it will return to the activity.
If it's no.2, it mean gallery will be started having pictures and videos for a user to select one and will return back to the activity.
Hello Umair,
I have done this type of application I searched many time but I didn't get any proper solution so I changed your my menu & they are now
1)Take New Photo
2)Take New Video
3)Existing Image/Video
Process will be like this
1)I use an global variable
2)So when user click on menu one I sets global variable value to 1
3) Start the activity for result like below
try{
System.gc();
String fileName = System.currentTimeMillis()+".jpg";
String mPathImage = Environment.getExternalStorageDirectory()+ "/" + fileName;
File file = new File(mPathImage);
Uri outputFileUri = Uri.fromFile( file );
Intent mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mIntent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult(mIntent, 1);
mValue=1;
}catch(Exception e){
}
If User click on menu 2 I change value of global variable to 2
& starts the activity for result like below.
try {
System.gc();
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, 1);
mValue=2;
}catch(Exception e){}
If user click on 3rd menu I set value to 3
& start the activity for result like below.
try{
System.gc();
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent,1);
mValue=3;
}catch(Exception e){}
}
This will show all the images & video's in mobile
Then finally when activity gets closed use global variable to check whether user want to new image or video or existing image/video.
Hope this will help you..
I'm developing an app for Android 2.1 upwards. I want to enable my users to select a profile picture within my app (I'm not using the contacts framework).
The ideal solution would be to fire an intent that enables the user to select an image from the gallery, but if an appropriate image is not available then use the camera to take a picture (or vice-versa i.e. allow user to take picture but if they know they already have a suitable image already, let them drop into the gallery and pick said image).
Currently I can do one or the other but not both.
If I go directly into camera mode using MediaStore.ACTION_IMAGE_CAPTURE then there is no option to drop into the gallery.
If I go directly to the gallery using Intent.ACTION_PICK then I can pick an image but if I click the camera button (in top right hand corner of gallery) then a new camera intent is fired. So, any picture that is taken is not returned directly to my application. (Sure you can press the back button to drop back into the gallery and select image from there but this is an extra unnecessary step and is not at all intuitive).
So is there a way to combine both or am I going to have to offer a menu to do one or the other from within my application? Seems like it would be a common use case...surely I'm missing something?
You can try doing something like this:
// ...
// Within your enclosing Class
// ...
private static final int SELECT_PICTURE = 1;
// ...
Intent pickIntent = new Intent();
pickIntent.setType("image/*");
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String pickTitle = "Select or take a new Picture"; // Or get from strings.xml
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra
(
Intent.EXTRA_INITIAL_INTENTS,
new Intent[] { takePhotoIntent }
);
startActivityForResult(chooserIntent, SELECT_PICTURE);
To see how to handle the activitiy's result, please refer to this question
Note: a critical point is how to determine whether the camera or gallery was used. That is shown in this code example: https://stackoverflow.com/a/12347567/294884
UPDATE: The other answer, using EXTRA_INITIAL_INTENTS, is a better one at this point. At the time I wrote my answer, EXTRA_INITIAL_INTENTS did not yet exist, as it was added in API Level 5.
So is there a way to combine both or
am I going to have to offer a menu to
do one or the other from within my
application?
Write your own gallery that has the features you desire.
I would think a menu would be simpler.
Seems like it would be a common use
case...surely I'm missing something?
The developer next to you will think the gallery should allow you to pick from the local gallery or else hop out to Flickr to make a selection from there. Another developer will think the camera should not only allow to "take a picture" via the camera but to "take a picture" via choosing something from the gallery, inverting things from the way you envision it. Yet another developer will think that the gallery should allow picking from the local gallery, or Flickr, or the camera, or a network-attached webcam. Still another developer will think that the gallery is stupid and users should just pick files via a file explorer. And so on.
All of this in an environment (mobile phones) where flash for the OS is at a premium.
Hence, IMHO, it is not completely shocking that the core Android team elected to provide building blocks for you to assemble as you see fit, rather than trying to accommodate every possible pattern.
You can proceed in this way in your Activity:
private static final int REQUEST_CODE_PICTURE= 1;
/**
* Click on View to change photo. Sets into View of your layout, android:onClick="clickOnPhoto"
* #param view View
*/
public void clickOnPhoto(View view) {
Intent pickIntent = new Intent();
pickIntent.setType("image/*");
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String pickTitle = "Take or select a photo";
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takePhotoIntent });
startActivityForResult(chooserIntent, REQUEST_CODE_PICTURE);
}
Then, add always in your Activity the method onActivityResult:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_PICTURE && resultCode == Activity.RESULT_OK) {
if (data == null) {
return;
}
try {
InputStream inputStream = getContentResolver().openInputStream(data.getData());
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imgPhoto.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
My Answer is almost identical to #Macarse solution but I also add an additional intent to show gallery apps (Ex: Google Photos) and is written in Kotlin:
val REQUEST_CODE_GET_IMAGE = 101
private fun addProfileImage() {
val pickImageFileIntent = Intent()
pickImageFileIntent.type = "image/*"
pickImageFileIntent.action = Intent.ACTION_GET_CONTENT
val pickGalleryImageIntent = Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
val captureCameraImageIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
val pickTitle = "Capture from camera or Select from gallery the Profile photo"
val chooserIntent = Intent.createChooser(pickImageFileIntent, pickTitle)
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(captureCameraImageIntent, pickGalleryImageIntent))
startActivityForResult(chooserIntent, REQUEST_CODE_GET_IMAGE)
}
Extract image from result intent:
private var imageTempFile: File? = null
private var imageMimeType: String? = null
private fun extractImage(intent: Intent?) {
val imageUri = intent?.data
imageUri?.let {
Glide.with(this)
.load(imageUri)
.into(profileImageCiv)
imageTempFile = MediaUtils.copyContentFromUriToCacheFile(this, imageUri, Settings.DIRECTORY_CACHE_TEMP_PROFILE_IMAGE)
imageMimeType = MediaUtils.getMimeType(this, imageUri)
} ?: run {
intent?.extras?.get("data")?.let { bitmap -> // Bitmap was returned as raw bitmap
Glide.with(this)
.load(bitmap)
.into(profileImageCiv)
imageTempFile = MediaUtils.writeBitmapToCacheFile(this, bitmap as Bitmap, Settings.DIRECTORY_CACHE_TEMP_PROFILE_IMAGE)
imageMimeType = "image/jpeg" // The bitmap was compressed as JPEG format. The bitmap itself doesn't have any format associated to it
} ?: run {
imageTempFile = null
imageMimeType = null
Log.e("Intent data is null.")
Log.d("Error during photo selection")
}
}
}