Development issue/problem:

Last update

The application for the function was carried out by Google. See the answer below.

Original question.

With an older version of Google Maps PI I was able to take a screenshot of a Google map to share it on social media. I used the following code to take a screenshot and save the image to a file, and it worked well:

public String captureScreen()
{
String storageState = Environment.getExternalStorageState() ;
Log.d(StorageState, StorageState state is : + memoryState) ;

// Picture name and path to include the extra sd-folder name you choose for the
String mPath file = this.getFilesDir().getAbsolutePath() ;

// Create a screenshot bitmap
Bitmap bitmap;
View v1 = this.mapView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false)) ;

OutputStream error = Null ;

String filePath = System.currentTimeMillis() + .jpeg ;

{
error = try openFileOutput(filePath,
WORLD_MODE_READABLE) ;

// Write a string to the file
bitmap.compress (Bitmap.CompressFormat.JPEG, 90, error);
error.flush();
error.close();
}
catch (FileNotFoundException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, FileNotFoundException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}
catch (IOException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, IOException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}

declaration formPad;
}

However, the new GoogleMap object used by the V2 Api does not have a getRootView() method like MapView.

That’s what I’ve been trying to do:

SupportMapFragment folderFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.basicMap)

View v1 = mapFragment.getView() ;

But the screenshot I receive has no map content and looks like this:

Has anyone figured out how to take a screenshot of the new Google Maps PI V2?

Update

I also tried to get the rootView this way:

View v1 = getWindow().getDecorView().getRootView() ;

The result is a screenshot that contains the action bar at the top of the screen, but the map is still blank, just like the screenshot I included.

Update

An application for a position has been sent to Google. Submit a request for a feature if you want Google to add it in the future: Screenshot function added to the Google Maps API V2

How can I solve this problem?

Solution 1:

Update – Google has added a snapshot method**. :

Asked for the Screen Capture method of the OpenGL layer of the Google Map V2 API of Android.

To take a screenshot, simply implement the following interface:

abstract public blank onSnapshotReady

and call us:

public final empty snapshot (GoogleMap.SnapshotReadyCallback callback)

An example that takes a screenshot and then presents the default image sharing options:

public void captureScreen()
{
SnapshotReadyCallback callback = new SnapshotReadyCallback()
{

@Override
public blank onSnapshotReady(Bitmap snapshot)
{
// TODO Method automatically generated stub
bitmap = snapshot ;

OutputStream error = Null ;

String filePath = System.currentTimeMillis() + .jpeg ;

{
error = try openFileOutput(filePath,
WORLD_MODE_READABLE) ;

// Write a string to the file
bitmap.compress (Bitmap.CompressFormat.JPEG, 90, error);
error.flush();
error.close();
}
catch (FileNotFoundException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, FileNotFoundException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}
catch (IOException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, IOException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}

openShareImageDialog(filePath);
}
}

mMap.snapshot (callback);
}

Once the image is captured, the default image sharing dialog appears, allowing the user to choose how to share the image:

Publicly void OpenShareImageDialog(String filePath)
{
File = this.getFileStreamPath(filePath) ;

if(!filePath.equals())
{
last ContentValues values = new ContentValues(2);
values.put(MediaStore.Images.MIME_TYPE, image/jpeg);
values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
last Uri contentUriFile = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values 😉

final intention = new intention (android.content.intention.intentionION_SEND);
int.setType(image/jpeg);
int.putExtra(android.content.intention.EXTRA_STREAM, contentUriFile);
startActivity(intention.createChooser(intent.createChooser(annent, Share Image))) ;
}
else
{
//Dit is the custom class I use to display the dialogs…. Just replace it with what you want to display as an error message, toast, etc.
DialogUtilities.showOkDialogWithText(this, R.string.shareImageFailed);
}
}

The documentation is here

Solution 2:

Below are the steps to follow to take a screenshot of Google Map V2 with an example.

Step one. Open the Android sdk manager (Windows > Android sdk manager) and develop Advanced now; update / install Google Play services in revision 10; skip this step if already installed.

Read here the notes https://developers.google.com/maps/documentation/android/releases#august_2013

Step two. Blackout on restart

Step 3 : Import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback ;

Step four. Select the screen/card image capture/save method as follows.

public void CaptureMapScreen()
{
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
Bitmap ;

@Override
public blank onSnapshotReady(Snapshot bitmap) {
// TODO Method stub automatically generated
bitmap = snapshot ;
try out {
FileOutputStream out = new FileOutputStream(/mnt/sdcard/
+ MyMapScreen + System.currentTimeMillis()
+ .png)

// via /mnt ….. png => this is the storage path (where the image is saved) + the name of the image, which you can customize.

bitmap.compress(Bitmap.CompressFormat.PNG, 90, off);
} catch (exception e) {
e.printStackTrace();
}
}
}.

myMap.snapshot(reminder) ;

// myMap is a GoogleMap object +> GoogleMap myMap;
// which is initialized in onCreate() =>
// myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
}

Step five. Now name this CaptureMapScreen() method where you want to take a snapshot.

In my case I call this method when the button on my onCreate() is pressed, which works fine.

like… :

Button btnCap = (button) findViewById(R.id.btnTakeScreenshot);
btnCap.setOnClickListener(new OnClickListener() {

@Override
public null and void onClick(View v) {
// TODO Automatically generated method stub
try {
CaptureMapScreen();
} capture (Exception e) {
// TODO : Treatment of the
e.printStackTrace();
} exception

}
});

Consult the document here and here

Solution 3:

I took a screenshot of the map, it’ll be useful.

GoogleMap private map;
LatLng latLong private static map ;

`

public void onMapReady(GoogleMap googleMap) {
map = googleMap;
setMap(this.map);
animateCamera();
map.moveCamera(CameraUpdateFactory.newLatLng)));
map.setOnMapLoadedCallback (new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
snapshot();
}
});
}).

`

the snapshot() method to obtain a screenshot of the map

public void snapShot(){
GoogleMap.SnapshotReadyCallback callback=new GoogleMap.SnapshotReadyCallback() {
bitmap ;
@Override
public void onSnapshotReady(Bitmap snapshot) {
bitmap=snapshot ;

try{
file=new file(Environment.getExternalStoragePublicDirectory(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),directory.png);
FileOutputStream error=new FileOutputStream (file);
bitmap.compress (Bitmap.CompressFormat.PNG,90,error);
Toast.makeText (PastValuations.this, Capture, Toast.LENGTH_SHORT).show () ;

catch (Exception e){
e.printStackTrace ();
Toast.makeText (PastValuations.this, Not Capture, Toast.LENGTH_SHORT).show ();
}.

Folder.snapshot (recall);
…}

My production under Capture screen shot of GoogleMap PI V2 –

Solution 4:

Edit: this answer is no longer valid – the request for screenshots in Google Maps PI V2 has been granted. Consider this answer as an example.

Original answer accepted

Since the new PI v2 cards are displayed in OpenGL, it is impossible to take a screenshot.

Solution No 5:

Since the most common answer does not work with polylines and other overlays on a map fragment (which I was looking for), I would like to share this solution.

public void captureScreen()
{
GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback()
{

@Check public blank
onSnapshotReady(Map Snapshot) {
try {
getWindow().getDecorView().findViewById(android.R.id.content).setDrawingCacheEnabled(true);
Bitmap backBitmap = getWindow().getDecorView().findViewById(android.R.id.content).getDrawingCache();
Bitmap bmOverlay = Bitmap.createBitmap(
backBitmap.getWidth(), backBitmap.getHeight(),
backBitmap.getConfig()));
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(snapshot, new Matrix(), null);
canvas.drawBitmap(backBitmap, 0, 0, null) ;

OutputStream error = Null ;

String filePath = System.currentTimeMillis() + .jpeg ;

{
error = try openFileOutput(filePath,
WORLD_MODE_READABLE) ;

// Write a string to the file
bmOverlay.compress (Bitmap.CompressFormat.JPEG, 90, error);
error.flush();
error.close();
}
catch (FileNotFoundException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, FileNotFoundException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}
catch (IOException e)
{
// TODO Automatically generated capture block
Log.d(ImageCapture, IOException);
Log.d(ImageCapture, e.getMessage());
filePath = ;
}

openShareImageDialog(filePath) ;

} capture (exception e) {
e.printStackTrace();
}
}
}

;

folder.snapshot (callback);
}

Solution No 6:

private GoogleMap mMap;
SupportMapFragment folderFragment;
LinearLayout linearLayout;
String jobId=1 ;

File;

Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState) ;
setContentView (R.layout.activity_maps) ;

linearLayout=(LinearLayout)findViewById (R.id.linearlayout);
// Get SupportMapFragment and receive a notification when the card is ready for use.
mapFragment = (SupportMapFragment)getSupportFragmentManager ()
.findFragmentById (R.id.map);
mapFragment.getMapAsync (this);
// Get Google Map snapshots.

}

/**
* Handle the card as soon as it is available.
* This reminder is activated when the card is ready for use.
* Here we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services are not installed on the device, the user will be prompted to install
* in the SupportMapFragment. This method will only be activated after user
* Google Play services is installed and returned to the application.
*/
@ Get
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap ;

// add marker to Sydney and move camera
LatLng to Sydney = new LatLng (-26.888033, 75.802754);
mMap.addMarker (new MarkerOptions ().position (sydney).title (Kailash Tower));
mMap.moveCamera (CameraUpdateFactory.newLatLng (sydney));
mMap.setOnMapLoadedCallback (new GoogleMap.OnMapLoadedCallback() {
@Override
public null and void onMapLoaded() {
snapShot();
}
}) ;
}

// Initialization of the snapshot method
public void snapShot(){
GoogleMap.SnapshotReadyCallback callback=new GoogleMap.SnapshotReadyCallback() {
bitmap;
@Override
public void onSnapshotReady(Bitmap snapshot) {
bitmap=snapshot;
bitmap=getBitmapFromView(linearLayout);
try{
file=new File (getExternalCacheDir(),map.png);
FileOutputStream error=new FileOutputStream (file);
bitmap.compress (Bitmap.CompressFormat.PNG,90,error);
Toast.makeText (MapsActivity.this, Capture, Toast.LENGTH_SHORT).show ();
sendSceenShot (file);
}catch (Exception e){
e.printStackTrace ();
Toast.makeText (MapsActivity.this, Not Capture, Toast.LENGTH_SHORT).show ();
}.

};mMap.snapshot (callback);
}
private Bitmap getBitmapFromView(view) {
Bitmap returnBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_888888);
Canvas canvas = new Canvas (returnBitmap);
Drawable bgDrawable = view.getBackground();
as (bgDrawable !=null) {
// has a background to draw, draw it on the canvas
bgDrawable.draw(canvas);
} else{
// has no background to draw, draw a white background on the canvas
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
returnBitmap;
}

// Run the api with the retrofit
private void sendSceenShot(File file) {
RequestBody job=null ;

Gson gson = new GsonBuilder ()
.setLenient ()
.create () ;

Retrofit retrofit = new Retrofit.Builder ()
.baseUrl (BaseUrl.url)
.addConverterFactory (GsonConverterFactory.create (gson))
.build () ;

final RequestBody requestBody = RequestBody.create (MediaType.parse (image/*), file);
job=RequestBody.create (MediaType.parse (text), jobId) ;

MultipartBody.PartToUpload = MultipartBody.Part.createFormData (name,file.getName(), requestBody) ;

API service = retrofit.create (API.class);
Call call=service.sendScreen (job,fileToUpload);
call.enqueue (new Callback() {
@Override
public null and void onResponse(Call call, Response response response) {
if (response.body ().getMessage ().equalsIgnoreCase (success)){
Toast.makeText (MapsActivity.this, success, Toast.LENGTH_SHORT).show ();
}
}

@Public Void
definition onFailure (Call call, Throwable t) {

}
});

}

}

Solution No 7:

I hope this will help you take a screenshot of your card.

Method call :

gmap.setOnMapLoadedCallback(mapLoadedCallback) ;

Explanation of the method :

last SnapshotReadyCallback snapReadyCallback = new SnapshotReadyCallback() {
bitmap bitmap;
@Override
public blank onSnapshotReady(Bitmap snapshot) {
bitmap = snapshot ;

Try

/Do something with your picture.

imageview.setImageBitmap(bitmap) ;

} capture (exception e) {e.printStackTrace();} capture (exception e) {e.printStackTrace()

}
};

GoogleMap.OnMapLoadedCallback mapLoadedCallback = new GoogleMap.OnMapLoadedCallback() {
@Override
public null and void onMapLoaded() {
gmap.snapshot(snapReadyCallback);
}
}

Solution No 8:

Eclipse DDMS can even capture the screen on a Google V2 map.

Try calling /system/bin/screencap or /system/bin/screenshot if you are root. I learned this from the way the Eclipse android implements DDMS screencapture.

Good luck!

You May Also Like

The Default Gateway Is Not Available in windows 10 (Solved)

Has your computer lost its internet connection after the Windows update? And…

How to Fix FFXIV Lobby Server Error 5006

RECOMMENDED: Click here to fix Windows errors and optimize system performance. It…

Chromebook compatible printers from HP, Canon, Epson and others

Lightweight Chromebooks are great for working on the Internet, but they don’t…

Having slow download speeds on Steam? Here’s the fix!

Opera GX Download Steam and all your favorite games with the world’s…