在屏幕截图上显示谷歌地图

时间:2015-01-28 17:39:11

标签: android eclipse google-maps screenshot screen-capture

好日子的家伙,我在eclipse上以编程方式进行屏幕截图,但它很成功,但谷歌地图片段只在我的屏幕捕获结果上显示黑页。我该怎么做才能在我的屏幕上显示地图?

这是我的代码:

public void download (View v){
View view = findViewById(R.id.layout_id);
view.setDrawingCacheEnabled(true);
Bitmap bitmap = view.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
//ImageView iv = (ImageView) findViewById(R.id.imageView1);
FrameLayout iv = (FrameLayout)findViewById(R.id.map);
//iv.setBackgroundDrawable(bitmapDrawable);

if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                //we check if external storage is available, otherwise display an error message to the user
               File sdCard = Environment.getExternalStorageDirectory();
               File directory = new File (sdCard.getAbsolutePath() + "/Transit_Guide_Downloads");
               directory.mkdirs();
               String filename = "download_" + i + ".jpg";
               File yourFile = new File(directory, filename);
               while (yourFile.exists()) {
                    i++;
                    filename = "download_" + i + ".jpg";
                    yourFile = new File(directory, filename);
               }
               if (!yourFile.exists()){
                    if (directory.canWrite())
                    {
                       try {
                             FileOutputStream out = new FileOutputStream(yourFile, true);
                             bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                             out.flush();
                             out.close();
                             Toast.makeText(SecondMap.this, "File exported to /sdcard/Transit_Guide_Downloads/screenshot" + i + ".jpg", Toast.LENGTH_SHORT).show();
                             i++;
                            } catch (IOException e) {
                            e.printStackTrace();

                    }
                }
            }}
            else
            {
                Toast.makeText(SecondMap.this, "SD Card not available!", Toast.LENGTH_SHORT).show();

}
             }           

1 个答案:

答案 0 :(得分:2)

如果您无法在设备上显示Google Map,则很可能是因为您没有在Google API KEY上获取Google地图v2 developer console并将其放入{{1} }}

有关如何逐步获取和显示地图的信息,您可以参考herehere