【问题标题】:Show google map on screen capture在屏幕截图上显示谷歌地图
【发布时间】:2015-01-28 17:39:11
【问题描述】:

大家好,我在 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();

}
             }           

【问题讨论】:

  • 您在哪里获取屏幕截图,是在模拟器上还是在真实设备上?因为我检查了我的设备,所以它工作正常。
  • 在我的物理设备上,程序可以运行,但地图片段只是黑色,没有显示地图。

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


【解决方案1】:

如果您无法在您的设备上显示Google Map,很可能是您没有在googledeveloper console上获取您的Google Map v2 API KEY并输入您的Androidmanifest.xml

地图的获取和展示方法可以参考herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多