(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.
Related
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 want to make a button that float on homescreen and also work if any other activity is in running.
i have tricked many ideas and also google vary much but i can't get still any solution..
for example i have tried to make my application transparent and full screen and as a system alert flag from this stackoverflow question: Creating a system overlay window (always on top)
#Override
protected void onStop(){
super.onStop();
Intent intent = new Intent(this, ClassNameOfYourActivity.class);
startActivity(intent);
}
and also tried to start my activity at every movement but it is very bad idea like this:
can't get any idea of doing this...Hopefully requested to share me any idea or example if you have experienced about this...
thanzzzz in advance..
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.
Hello I'm using built in Google Map to show route to user.
When I click on get route button I have written the following code.
String mapURL="http://maps.google.com/mapssaddr="
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude()
+","+restaurant.getLongitude();
Intent i=new Intent("android.intent.action.VIEW",Uri.parse(mapURL));
startActivity(i);
This code Works fine and also displayed route from current location to destination location..
When I come back to my application from Google Maps ,my application start from first.
Can any one suggest me what to do?
Can you please try the code below
String uri="http://maps.google.com/mapssaddr="
+GlobleVeriable.getCurrentLocation().getLatitude()+","+GlobleVeriable.getCurrentLocation().getLongitude()+"&daddr="+restaurant.getLatitude()
+","+restaurant.getLongitude();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
intent.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(intent);
It's just the average Android behavior. What you can do is to save the current state of the application to some file, right before starting the Google Maps activity. On resume, you can load that file and restore the application manually.
I think it's the only way. It's been a while since I browsed the Android documentation. I do remember something like "... the operating system may terminate your application at any time if inactive, so it's the developer's responsibility to save any user-sensitive information before the application goes inactive".
I'd save within the onPause() method, and load within onResume().
I have an activity which allows me to take an image with the camera, and I want to send this image to the parent activity as an Intent extra. However, if I actually try to add the image to the intent, all of a sudden the finish() call never seems to do anything and my activity never closes.
Here's some of my code:
public void onPictureTaken(byte[] imageData, Camera c)
{
if (imageData != null) {
// Send the result as a byte array
Intent intent = new Intent();
intent.putExtra("imagedata", imageData);
setResult(RESULT_OK, intent);
finish();
}
}
The odd thing is, if I comment out the putExtra() call then it all works properly (without the image, of course) and my activity closes and I hit the parent's onActivityResult() callback. But if I leave the line in, then the activity never closes and the callback never fires.
I've tried putting more trivial things in the extras, like strings, and it's all worked perfectly. putExtra() is allowed to take a byte array and I've even tried wrapping it up as a Bitmap and sending that, but it didn't work either. The only thing I can think of is that I'm just not supposed to pass something that big into an Intent, in which case I guess I'll just try writing it to a file instead. It's just that writing is to a file should be slower than just passing the byte array reference around, which is why I'm trying to do it this way.
Any ideas? Thanks in advance :)
Phone: Samsung Galaxy S
API level: 7
You shouldn't be including your image data within the Intent extras. See this thread for clarification. In a nutshell, keep your Intent extras as small as possible.
I would suggest storing your picture to the SD card, and passing the path to this file in your Intent.
try this code
public void quit() {
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
System.exit(0);
}
and call it using quit();