2016-08-26 139 views
-4

如何让Android OS Phone每分钟显示屏幕截图并通过电子邮件发送?如何获得手机显示屏幕?

+0

这是可能的,但在代码中已经做了任何进展?如果是这样,请更新您的问题并发布您的代码,并详细描述您的需求,帮助我们为您提供帮助! –

+1

您的问题目前太宽泛。请告诉我们您是否尝试过任何东西,以及是否有特定问题。 – Praveen

+0

我不知道拿显示屏幕 –

回答

0

使用下面的代码从移动

private void takeScreenshot() { 
    Date now = new Date(); 
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); 

    try { 
     // image naming and path to include sd card appending name you choose for file 
     String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg"; 

     // create bitmap screen capture 
     View v1 = getWindow().getDecorView().getRootView(); 
     v1.setDrawingCacheEnabled(true); 
     Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
     v1.setDrawingCacheEnabled(false); 

     File imageFile = new File(mPath); 

     FileOutputStream outputStream = new FileOutputStream(imageFile); 
     int quality = 100; 
     bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); 
     outputStream.flush(); 
     outputStream.close(); 

     openScreenshot(imageFile); 
    } catch (Throwable e) { 
     // Several error may come out with file handling or OOM 
     e.printStackTrace(); 
    } 
} 

添加权限获取截屏中你的清单

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

这是你可以打开最近生成的图像:

private void openScreenshot(File imageFile) { 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 
    Uri uri = Uri.fromFile(imageFile); 
    intent.setDataAndType(uri, "image/*"); 
    startActivity(intent); 
} 
相关问题