protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
//Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
//cameraIntent.putExtra(
// MediaStore.EXTRA_OUTPUT, (new File(Environment.getExternalStorageDirectory(),
// String.valueOf(System.currentTimeMillis()) + ".jpg"))
//);
startActivityForResult(cameraIntent, 3220);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 3220){
Log.d("ank", "activity");
}
Log.d("ank", "activity1");
}
I am not able to get onActivityResult when I use Intent_ACTION_VIDEO_CAMERA or Intent_Action_Still_Image_Camera
When I use Action_Image_Capture then i am getting onActivityResult called out.
I want to use the above two Intents only because when using Action_Image_Camera video option do not come
I am not able to get onActivityResult when I use Intent_ACTION_VIDEO_CAMERA or Intent_Action_Still_Image_Camera
Neither INTENT_ACTION_STILL_IMAGE_CAMERA nor INTENT_ACTION_VIDEO_CAMERA are documented to return a result. I would expect most apps supporting those Intent actions to not return a result.
Related
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivity(intent);
1.How can I get an URI of music file using code above?
2.If I have Uri already, how set it as ringtone or alarm?
Also tried use:
Convert a file path to Uri in Android
To get a return result from an activity, use startActivityForResult instead of startActivity.
private int REQUEST_ACTION_PICK = 1;
...
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
// startActivity(intent);
startActivityForResult(intent, REQUEST_ACTION_PICK); //fixme
// ...
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ACTION_PICK && resultCode == RESULT_OK) {
Uri uri = data.getData();
Log.d(TAG, uri.toString());
}
}
As for 'how set it as ringtone or alarm?', perhaps this might work?
Set default alarm sound programatically Android
I've an android application where in an activity the user chooses a picture from the phone's memory to upload it to the server using the Action Pick intent
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
However; now the requirements has changed and the client wants to upload any file with any extension, what intent should I use in order to open the phone's memory (like the file manager) and choose whatever I want?
Now I'm using the Get content intent thanks to you guys:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 1);
but the problem is in the start activity for result
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
Log.d("select pivture", "passed her");
Uri selectedMediaUri = data.getData();
String Fpath = selectedMediaUri.getPath();
Log.d("Fpath", Fpath);
}
I get as follows:
/document/primary:Download/tool208.pdf
Which is not what I want, I want path like this one:
/external/images/media/6634
Use below method:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
UPDATE
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==PICKFILE_REQUEST_CODE){
}
}
I'm working on some code someone else wrote and I'm having trouble handling the result of a camera intent.
Basically i have a DashBoardActivity which contains a tab with a fragment called "MyProfileContainer", which contains a "SettingsFragment" fragment which contains a "EditProfileFragment"fragment.
In the EditProfileFragment the user can take a picture for his profile. It works but it calls the onActionResult on the Dashboard Activity.
I read some guide on how to redirect it to the EditProfileFragment but I haven't been able to do it.
I'm losing literally days on this one and I can't figure it out.
This is onActivityResult on the Dashboard Activity
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
And this is EditProfileFragment
private Uri imageUri = null;
public void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
getParentFragment().startActivityForResult(intent, 100);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == Activity.RESULT_OK) {
Uri selectedImage = imageUri;
getActivity().getContentResolver().notifyChange(selectedImage, null);
ContentResolver cr = getActivity().getContentResolver();
Bitmap bitmap;
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
profilePhoto.setImageBitmap(bitmap);
Toast.makeText(getActivity(), selectedImage.toString(),
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getActivity(), "Failed to load", Toast.LENGTH_SHORT)
.show();
Log.e("Camera", e.toString());
}
}
}
I don't know if I have to override the method on every class between this two or if I'm doing something else wrong, but I'm sure the EditProfileFragment onActivityResult is never called.
I found out the problem, and it was actually a bug of Android.
The fragment that was to recieve the result was a fragment nested inside other fragment and the method call was not properly propagated that deeply.
I had to override the method on the containing fragment manually and it worked.
The easy trick to call OnActivityResult in nested fragment.
1) Add this code in your captureImage method it will start a new activity.
Intent intent = new Intent(getContext(), CameraPreviewActivity.class);
startActivityForResult(intent, 111);
2) Now CameraPreviewActivity activity will open and it will start camera activity and returns the result to fragment.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, FragmentAccPhoto.REQUEST_IMAGE_CAPTURE);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
setResult(RESULT_OK, data);
finish();
}
I read an text input from the user, this input i use it as a name of a picture i'm taking by the camera.
i store this name and the path of the image name into Sqlite Database.
what I'm trying to do is, after clicking OK to accept the taken picture, i want the saved path to be displayed in a toast.
the problem is, when I click OK to accept the picture, nothing is being displayed and i cant switch from the camera activity to the activity that called the camera activity"the previous activity"
Note: I'm using the emulator not a real device.
OnClickListener btn_TakePictureListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String imgPath = retrievePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(imgPath));
startActivityForResult(intent, RequestCode);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCode && resultCode == RESULT_OK) {
String s = data.getData().toString();
Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
}
}
if you are passing Uri for you image then you can retrieve image as taken by camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
Environment.getExternalStorageDirectory(), "temp.jpg")));
startActivityForResult(intent, 1);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
// Set the file save path with directory
File picture = new File(Environment.getExternalStorageDirectory()
+ "/temp.jpg");
Uri imageuri= Uri.fromFile(picture);
//set to imageview here
}
}
EDIT:
For Getting data uri in onActivityResult start Camra Activiyt as:
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);
startActivityForResult(intent, 2);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
Uri uriimg = data.getData();
Toast.makeText(getBaseContext(), ""+uriimg.toString(), Toast.LENGTH_SHORT).show();
}
}
When I my app is launched I am showing a splash screen. That page is been shown for 10 sec, running on a thread.
When it switches over to new activity on a result I want o hit a URL in server and I will be getting a return value which I can use for my further implements.
Here is my code:
private final int SPLASH_DISPLAY_LENGHT = 1000;
new Handler().postDelayed(new Runnable()
{
#Override
public void run()
{
Log.e("Handler ","run");
Intent myIntent = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(myIntent, imgDL);
finish();
}
}, SPLASH_DISPLAY_LENGHT);
public void onActivityResult(int requestCode, int resultCode, final Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == imgDL)
{
Log.e("onActivity Result","");
urlHitMethod("http://XXXXXXXXXXXXXXXXXX.com/banner_scan");
}
}
But here the onActivityResult is not called. How to fix this?
Also, please note than if you base activity (the one calling startActivityForResult) can't use the flag noHitory in the manifest.
If you do so, onActivityResult will never be called.
try this
Intent myIntent = new Intent(activity.this, CaptureActivity.class);
and
#Override
public void onActivityResult(int requestCode, int resultCode, final Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == imgDL)
{
Log.e("onActivity Result","");
urlHitMethod("http://XXXXXXXXXXXXXXXXXX.com/banner_scan");
}
if(resultCode==RESULT_OK)
{
Log.e("onActivity Result","come in onactivity result ok");
}
else
{
Log.e("onActivity Result","come in onactivity result with error");
}
}
If you are using onActivityResult, then you should not finish the activity when starting with intent otherwise it will crash the app.
Thanks.
In the CaptureActivity.class you have to set the result and then check in the onActivityResult in the First Activity the result code
In the CaptureActivity.class it should be like the following
Intent in = new Intent();
setResult(1,in);//Here I am Setting the Requestcode 1, you can put according to your requirement
finish();