I'm trying to start the camera activity from my application
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
thats ok, after few seconds (lets say 10) I want to dispatch the touch event
and simulate the operation of taking a picture (long touch on the screen).
after that I want to catch the result back in my app...
protected void onActivityResult(int requestCode, int resultCode, Intent data)
do you have any idea how can I perform that?
thanks.
Sorry, but you cannot send a touch event to another app. Even if you could, it would not help, as there are thousands of camera apps, which use a variety of trigger mechanisms for taking a picture.
Either allow the user to take the picture, or you will need to work with the camera hardware in your own app, rather than use a third-party app.
Related
i just want to know is there any way to launch the front camera using just intent. i don't want to use intent.putextra thing. so basically my code should look like this
btnFrontCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent camera = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(camera);
}
});
But above code is launching the back camera. i want to launch the front camera directly.
Help me with this if it is possible in Android.
i just want to know is there any way to launch the front camera using just intent
No.
i don't want to use intent.putextra thing.
That is fine, as there is no "intent.putextra thing" that controls which hardware camera the user's chosen camera app will use. The choice of camera is between the camera app and the user, through the camera app's UI. You do not get a vote.
If you want to take a picture and force that to be taken using a front-facing camera (if one is available), you will need to take the picture yourself using the camera APIs, not by invoking a third-party camera app.
(First of all, sorry about my english)
I'm callig map activity from my main activity by this way:
String coord="geo:0,0";
Intent intent= new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse(coord));
startActivityForResult(intent,2);
...and is working fine. By the other side, i have onActivityResult:
public void onActivityResult(int request,int result,Intent intent){
//I think here should be the screenshot code
}
... which is called when the map activity finishes, and is also working fine.
Now, what I need is to take a screenshot (image, bitmap or drawable, i don't mind) of the map view at the moment that the map activity is getting closed (The final map), and i dont know if it is posible.
Thanks a lot
First, you cannot take a screenshot of another app, unless your app is running with superuser privileges and you use various undocumented techniques.
Second, by the time onActivityResult() is called, the map activity is not necessarily visible anymore.
im trying to take a picture inside an android app, and im trying to use the android devloper tutorial:
http://developer.android.com/training/camera/photobasics.html
they bring the following code:
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
}
i can't understand what is this action code and what it should be for taking pictures
thanks!
Per Getting a Result from an Activity, the second parameter to startActivityForResult is used to distinguish between multiple different requests (say, if you got results from both the camera and the gallery you'd want to know where the result is from).
That same actionCode is then returned as the requestCode in onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
The point is that it doesn't matter exactly what the number is (0, 1, 100, 5439, whatever), only that it is unique within your Activity. Therefore if you are only calling startActivityForResult in one place for one result, any number will do (as there is nothing to conflict with)
Intents are designed to allow your application to interact with others. In this case, your application will bring up the camera app, and the result will be sent back into your app.
A great place to get started with understanding this is, is the Android training "Interacting with Other Apps".
I am launching a media intent to take a photo. After the user took a picture and gets back to the previous activity the whole application has restarted.
As this doesn't happen all the time, I think my application goes to the background and android kills it when the device has low memory.
Is there any way to keep my application from going to the background?
Thanks!
This is normal behavior in Android, all activities currently not visible on screen (after onStop) can be killed without notice (i.e. onDestory) if the system has low memory.
This usually happens to our app on one of our test devices which has memory issues regardless of our app.
You can usually recreate this behavior when you open the camera via the intent, and then rotate the device (portrait to landscape), this will also kill and re-create your app.
To solve this you need to extend onSaveInstanceState and use the savedInstanceState parameter in your onCreate to pass from your killed instance to your new instance some important information (like "we're in the middle of getting a pic from the camera").
I can think of two possibilities...
It's not killing the activity, but the intent launches a new activity. You can stop this by putting a tag in your manifest.xml as an attribute in the activity tag like this:
<activity
android:name=".nameOfActivity"
android:launchMode="singleTop" />
Make sure that the media intent is under the activity to handle the photo, and not a main/launcher activity.
IMO two options:
Implement onSaveInstanceState/onRestoreInstanceState
or
Make your activity a service.
I faced this issue and got a solution after R&D for it.
Set Target Android 4.0 and then add this line in AndroidManifest.xml of activity:
android:configChanges="screenLayout|uiMode|orientation|screenSize|smallestScreenSize"
It works for me.
When you start media intent use following method instead of startActivity(intent)
startActivityForResult(intent, REQUEST_CODE); //private int REQUEST_CODE = 232
When the started activity finishes, your calling activity will be started. You need to handle this using following function
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
//Perform your task
}
}
The activity started need to override follwoing method
#Override
public void onBackPressed() {
Intent intent = new Intent();
setResult(REQUEST_CODE, intent);
super.onBackPressed();
}
startActivityForResult() is an special way for starting activity for a specific task and get the desired result. The called activity will send the data back.
You can use the method putExtra() & getExtra in intent to send and receive data between two activity.
This will solve your problem hopefully.
If you have doubts comment. And if possible share your code so it can be more clear.
I'd like to launch a video capture Intent that calls me back with some kind of result. So far it correctly launches the G1's default Camcorder app, but when I finish recording the video in Camcorder, it just sits there (still in the Camcorder app) instead of calling my onActivityResult() method.
Is this just a shortcoming of Camcorder, or is there a special flag or extra I can set to tell it to return control when it's done recording? Ideally it would pass me back a handle to the video - a URI, an InputStream, a file path.
The code:
protected void launchRecordVideoActivity() {
Intent intent = new Intent (android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult (intent, RequestCodes.RECORD_VIDEO);
}
RequestCodes is my own interface containing int constants.
public void onActivityResult (int requestCode, int resultCode, Intent intent) {
...
}
The contents of onActivityResult don't matter because my app is never called back at all.
onActivityResult is not being called.
Any suggestions? I can also bake the video recording directly into the app, but I'd prefer not to.
You can't (generally) call startActivityForResult on an intent that starts an application outside of your application
Same code works fine on SE x10 (updated to sdk 2.1). Activity starts, user starts recording video and when he press stop - video onActivityResult() is run in calling class.
Probably it was fixed in later SDK releases.