1

I try @Tarsem answer already but have fatal error occur can I know why? @Tarsem answer: https://stackoverflow.com/a/18308611/2398886

<--- these are my error codes in eclipse: --->

08-21 18:52:23.399: W/dalvikvm(29376): threadid=1: thread exiting with uncaught exception (group=0x40018578)

08-21 18:52:23.409: E/AndroidRuntime(29376): FATAL EXCEPTION: main

08-21 18:52:23.409: E/AndroidRuntime(29376): java.lang.NoClassDefFoundError: com.example.testing01.MainActivity2$6

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2.CaptureMapScreen(MainActivity2.java:410)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2$3.onClick(MainActivity2.java:182)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View.performClick(View.java:2485)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View$PerformClick.run(View.java:9080)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.handleCallback(Handler.java:587)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.dispatchMessage(Handler.java:92)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Looper.loop(Looper.java:130)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.app.ActivityThread.main(ActivityThread.java:3687)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invokeNative(Native Method)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invoke(Method.java:507)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:867)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

08-21 18:52:23.409: E/AndroidRuntime(29376): at dalvik.system.NativeStart.main(Native Method)

<--- these are my error codes in eclipse: --->

and these are my coding, is it my coding any bug?

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

             @Override
             public void onSnapshotReady(Bitmap snapshot) {
                 // TODO Auto-generated method stub
                 bitmap = snapshot;
                 try {
                     FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                         + "MyMapScreen" + System.currentTimeMillis()
                         + ".png");

                     // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

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

         map.snapshot(callback);

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

my Stop Button function:

//End Button Function
 Button timerStopButton = (Button) findViewById(R.id.btnTimerStop);      
 timerStopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view){          

            String latitude3=Double.toString(latitude1);
            String latitude4=Double.toString(latitude2);
            String longitude3=Double.toString(longitude1);
            String longitude4=Double.toString(longitude2);
            String Kcalories=String.format("%.2f", calories);

            Intent intent = new Intent(view.getContext(),NewDataActivity.class);
            intent.putExtra("lat1", latitude3);
            intent.putExtra("lat2", latitude4);
            intent.putExtra("long1", longitude3);
            intent.putExtra("long2", longitude4);
            intent.putExtra("timer", timerStop1);
            intent.putExtra("distance", distance2 + " m");
            intent.putExtra("Ccalories", Kcalories + " kcal");
            Toast.makeText(getApplicationContext(), "Calories (kcal):" + Kcalories, Toast.LENGTH_LONG).show();
            startActivity(intent);                                          

            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            //kill task timer and other 
            int pid = android.os.Process.myPid();
            android.os.Process.killProcess(pid);
        }                

 });

Is it my coding have any bug or my logic any probelm? can anyone help me? thanks :)

Community
  • 1
  • 1
俊祥 李
  • 35
  • 5

1 Answers1

1

Note Your code to Capture Map Screen is Correct and if still you have confusion than

Please Make sure Each Step Below:-

Below are the steps to capture screen shot of Google Map V2 with example

Step 1. open Android Sdk Manager (Window > Android Sdk Manager) then Expand Extras now update/install Google Play Services to Revision 10 ignore this step if already installed

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

Step 2. Restart Eclipse

Step 3. import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;

Step 4. Make Method to Capture/Store Screen/image of Map like below

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

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                // TODO Auto-generated method stub
                bitmap = snapshot;
                try {
                    FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                        + "MyMapScreen" + System.currentTimeMillis()
                        + ".png");

                    // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

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

        myMap.snapshot(callback);

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

Step 5. Now call this CaptureMapScreen() method where you want to capture the image

in my case i am calling this method on Button click in my onCreate() which is working fine

like:

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

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

        }
    });

Check Doc here and here

Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
  • 1
    Sorry about that, can I ask more... the capture screen only the map? If I want capture whole page, can I? and the code bitmap.compress(Bitmap.CompressFormat.PNG, 90, out), the 90 means what? Sometimes I see have other programmer fill 100... Thanks – 俊祥 李 Aug 21 '13 at 15:28
  • its about Quality of image, `quality Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting ` – Tarsem Singh Aug 21 '13 at 15:58
  • Yes, I done it... Do you know how to use Geopoint function? cos I possible change my function to Geopoint function? If any problem can asking you again? – 俊祥 李 Aug 21 '13 at 16:55
  • @俊祥李 see accepted answer here http://stackoverflow.com/questions/18309625/how-can-i-take-merge-screen-shot-of-google-map-v2-and-layout-of-xml-both-program to capture whole Page as you asked in your first Comment ! – Tarsem Singh Aug 22 '13 at 06:27
  • Here have one problem again, can you help me? Thanks http://stackoverflow.com/questions/18394665/how-to-increase-the-accuracy-of-my-start-position – 俊祥 李 Aug 23 '13 at 05:52
  • @Tarsem i have follwed your code and have updated googleplayservices to revision 12 but still I'm getting NoClassDefFoundError for SnapshotReadyCallback, please help – Ari Oct 26 '13 at 12:04