SORU
18 NİSAN 2010, Pazar


Nasıl programlama yoluyla Android bir ekran görüntüsü almak?

Nasıl kod herhangi bir program tarafından değil, ama telefon ekran seçilen bölgenin ekran görüntüsü alabilir miyim.

CEVAP
13 NİSAN 2011, ÇARŞAMBA


İşte benim ekran sd kartta saklanan ve daha sonra ihtiyaçlarınızı ne için kullanılacak izin kodu:

İlk olarak, uygun izin dosya kaydetmek için ekleyin:

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

Ve bu kodu (bir aktivitede çalışan):

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();
    }
}

Ve bu son zamanlarda oluşturulan resmi açmak için:

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);
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Qmusic Romania

    Qmusic Roman

    8 Temmuz 2011
  • tseyina

    tseyina

    2 AĞUSTOS 2006
  • Videojug

    Videojug

    25 EKİM 2006