2016-08-26 138 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); 
} 
相關問題