Android : How to get the screenshot of google map programmatically in android?

on Friday, July 4, 2014


Hi i am using google map in my android application, while i am taking the screenshot by clicking an imageview, it tooks the screenshot but googlemap and the included layout files does not include. Can anyone plz help me for that. Sorry for my poor english


My layout file is:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/main_page" >

<com.extraslice.gmobile.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:dragView="@+id/name"

sothree:panelHeight="48dp"
sothree:paralaxOffset="100dp"
sothree:shadowHeight="0dp" >


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="40"
map:cameraTargetLng="-100"
map:cameraZoom="4" />

<ImageView
android:id="@+id/logout_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginTop="30dp"
android:onClick="onLogout"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/email_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="30dip"
android:layout_marginTop="80dp"

android:src="@drawable/email_icon" />

<ImageView
android:id="@+id/compass"
android:layout_width="55dip"
android:layout_height="55dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dip"
android:onClick="compassClick"
android:src="@drawable/compass" />

<ImageView
android:id="@+id/golden_globe"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="80dp"
android:layout_marginRight="30dp"
android:onClick="onGoldenGlobe" />

</RelativeLayout>

</com.extraslice.gmobile.SlidingUpPanelLayout>

<include
layout="@layout/agentremotecontrol"
android:visibility="gone" />

<include
layout="@layout/agent_details"
android:visibility="gone" />


</RelativeLayout>


and the code to take the screenshot is:



email_icon.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

if (!mainLogin.isShown()) {

Toast.makeText(getApplicationContext(), "email_icon clicked", Toast.LENGTH_SHORT).show();


//View v1 = getWindow().getDecorView().getRootView();
// View v1 = iv.getRootView(); //even this works
View v1 = findViewById(R.id.main_page); //this works too
// but gives only content
v1.setDrawingCacheEnabled(true);
myBitmap = v1.getDrawingCache();

Log.i("777777777777myBitmap", ""+myBitmap);

// myBitmap.recycle();


// v1.setDrawingCacheEnabled(false); // clear the cache here
saveBitmap(myBitmap);
}


}
});

public void saveBitmap(Bitmap bitmap) {
String filePath = Environment.getExternalStorageDirectory()
+ File.separator + "Pictures/screenshot.png";
File imagePath = new File(filePath);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
sendMail(filePath);
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
public void sendMail(String path) {


Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "athulya@extraslice.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"giMobile ScreenShot");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Sent from my AndroidTab");
emailIntent.setType("image/png");
Uri myUri = Uri.parse("file://" + path);
emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));


}


Thanks in Advance.


0 comments:

Post a Comment