2013-07-26 55 views
2

我想知道是否可以截取手機並將其保存在我的圖庫中。像Windows上的打印屏幕功能一樣,有沒有類似Android的東西?有沒有任何代碼可以打印我的應用程序的屏幕?Android - Eclipse屏幕截圖代碼

回答

0

我不確定是否要以編程方式或手動方式執行此操作。當你說'像Windows中的PrintScreen時,我假設你想手動截圖。您可以在Android OS附帶的不同手機型號中使用不同的按鈕組合。 How to take screenshots on Android博客列出了您可以在不同型號的Android手機中截取屏幕截圖的各種方式。希望這可以幫助。

2

這些是可能的方式來做到這一點。

  • 如果你想利用模擬器的屏幕截圖或連接的設備在Eclipse,然後

打開Android視圖 「設備」(在窗口 - >顯示視圖 - >其他.. 。 - > Android - >設備)。點擊您想要拍攝屏幕截圖的設備或模擬器,然後單擊「屏幕截圖」按鈕並將其保存到您想要的任何位置。

  • 如果你想你的應用程序的屏幕截圖程序然後按照答案在這裏:How to programmatically take a screenshot in Android? 下面一些技巧使用shell命令需要將手機紮根。

    這是上面的鏈接示例代碼。

    // image naming and path to include sd card appending name you choose for file 
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "img_name.jpg"; 
    
    // create bitmap screen capture 
    Bitmap bitmap; 
    View v1 = getWindow().getDecorView().findViewById(android.R.id.content); 
    v1.setDrawingCacheEnabled(true); 
    bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
    v1.setDrawingCacheEnabled(false); 
    
    OutputStream fout = null; 
    Uri uri = Uri.fromFile(new File(mPath)); //can used as uri 
    
    try { 
        fout = new FileOutputStream(imageFile); 
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); 
        fout.flush(); 
        fout.close();  
    } catch (FileNotFoundException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
    } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
    } 
    
  • 而@Shobhit說,如果可以的話,你可以通過製造商快捷方式截圖。這裏是一些參考,如果你需要:http://www.makeuseof.com/tag/6-ways-to-take-screenshots-on-android/

+0

謝謝,我只是在找這個。所以我只能在rooted android設備上測試它嗎? – user2610342

+0

@ user2610342:除一些外,這也可以在無根設備上工作。 – dakshbhatt21

+1

@ user2610342:如果您在這裏找到您的答案,請將其標記爲已接受,這將有助於其他用戶。任何upvote將appriciated。 – dakshbhatt21