2016-02-16 10 views
5

मैंने देखा है चेतावनी के एंड्रॉयड में स्क्रीनशॉट लेने के लिए निम्नलिखित Link और यह शीर्ष जवाबप्रोग्राम संवाद

हालांकि साथ एक स्क्रीनशॉट ले करता है, क्या मैं चाहता हूँ है एप्लिकेशन का एक स्क्रीनशॉट लेने के लिए के लिए अलर्ट संवाद जो मैं उपयोगकर्ता को प्रदर्शित कर रहा हूं, उपर्युक्त समाधान और नीचे कोड केवल चेतावनी संवाद के पीछे क्या है और इसलिए कोई अच्छा

यहां कोड का उपयोग किया जा रहा है यदि कोई भी नहीं चला है लिंक प्रदान किया गया

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

संपादित करें: संवाद के लिए कोड के रूप में अनुरोध

public void showCalc(String title, String message) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setCancelable(true); 
    builder.setTitle(title); 
    builder.setMessage(message); 
    builder.setPositiveButton("Capture + Open", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        //Remove Values From Inventory 
        captureScreenAndOpen(); 

       } 
      }); 

    builder.setNegativeButton("Capture", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        captureScreen(); 
        Context context = getApplicationContext(); 
        Toast.makeText(context, "Screenshot Captured", Toast.LENGTH_LONG).show(); 
       } 
      }); 

    builder.setNeutralButton("Return", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    builder.show(); 
} 

को और संपादित:

यहाँ आप दो स्क्रीनशॉट देखेंगे, जब सब कुछ संवाद से स्क्रीनशॉट में सहेजा गया है पहले सहेजा गया स्क्रीनशॉट दिखाया जा रहा है, तो आप ' नीचे ध्यान दिया जाएगा कि पाठ का एक छोटा सा हिस्सा है जो हमेशा नीचे मौजूद होता है। जहां संवाद संवाद स्क्रॉल है, ताकि आप सभी डेटा देख सकते हैं में इतना पाठ नहीं है

Screenshot1

दूसरा स्क्रीनशॉट है, तो आप देखेंगे कि पहले स्क्रीनशॉट में नीचे स्ट्रिंग मौजूद नहीं है

Screenshot2

मैं इसे करना चाहते हैं कि सभी डेटा प्रदर्शित किया जाता है यदि संभव हो तो, मैं नहीं यकीन है कि हालांकि अगर एक स्क्रीनशॉट समारोह ऐसा करने में सक्षम होगा या कर रहा हूँ एक वैकल्पिक पद्धति

+0

कृपया अपना संवाद कोड पोस्ट करें। – Rohit5k2

+0

क्या आप केवल संवाद के स्क्रीनशॉट चाहते हैं? क्योंकि मैंने अभी इसके लिए एक कोड विकसित किया है। – Rohit5k2

+0

यह मजेदार था: किसी प्रश्न का उत्तर देने के लिए कोड विकसित करना। : डी – Rohit5k2

उत्तर

5

Android पर 5 एमुलेटर और उसके काम कर विकसित। आपके द्वारा प्रदान किए गए लिंक से अपना संवाद कोड और स्क्रीनशॉट कोड लिया।

यह आपके AlertDialog

public void showCalc(String title, String message) { 
    final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setCancelable(true); 
    builder.setTitle(title); 
    builder.setMessage(message); 
    builder.setPositiveButton("Capture + Open", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        //Remove Values From Inventory 
        captureScreenAndOpen(); 
       } 
      }); 

    builder.setNegativeButton("Capture", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        AlertDialog dialog2 =AlertDialog.class.cast(dialog); 
        takeScreenshot(dialog2); 
        Context context = getApplicationContext(); 
        Toast.makeText(context, "Screenshot Captured", Toast.LENGTH_LONG).show(); 
       } 
      }); 

    builder.setNeutralButton("Return", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
     } 
    }); 
    builder.show(); 
} 

यह स्क्रीनशॉट कोड

private void takeScreenshot(AlertDialog dialog) { 
    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 = "/data/data/com.rohit.test/test.jpg"; // use your desired path 

     // create bitmap screen capture 
     View v1 = dialog.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(); 

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

स्क्रीनशॉट लिया

enter image description here

Note1 है: आप metho सामान्यीकरण कर सकते हैं डी takeScreenshot यदि आप तर्क प्रकार को View पर बदलते हैं और dialog.getWindow().getDecorView().getRootView(); को इस विधि कहां से संवाद कोड में ले जाते हैं।

नोट 2: आपने अद्यतन प्रश्न देखा। मुझे नहीं लगता कि आप स्क्रीनशॉट में पूरा डेटा प्राप्त कर सकते हैं जब उनमें से कुछ छुपाए जाते हैं। इसे सामान्य स्क्रीनशॉट (कंप्यूटर या यहां तक ​​कि फोन पर) के रूप में सोचें। आप केवल वही तस्वीर लेते हैं जो आप देख सकते हैं।

+0

धन्यवाद, यह कोड अब बहुत अच्छा काम कर रहा है, अच्छी तरह से ... कभी-कभी संदेश बॉक्स स्क्रॉल करने में सक्षम होता है, यह शायद एक कदम बहुत दूर है, लेकिन क्या आप इस तरह से जानते हैं कि स्क्रीनशॉट सबकुछ बचा सकता है संवाद में और न सिर्फ क्या देख रहा है? – Sjharrison

+0

इस कोड में मैंने जो देखा है वह पूरा संवाद है। तो संवाद पर जो कुछ भी होगा, उसे पकड़ा जाएगा। – Rohit5k2

+0

मैं बेहतर प्रश्न – Sjharrison

2

इस पुस्तकालय बाहर का प्रयास करें:

https://github.com/jraska/Falcon

यह अपने स्क्रीनशॉट के लिए संवाद पर कब्जा कर सकते हैं।

0

1. मेरे प्यारे दोस्त आप एक चीज गलत कर रहे हैं जिसके द्वारा आप संवाद बॉक्स का स्क्रीनशॉट नहीं ले पा रहे हैं।

View v1 = getWindow().getDecorView().getRootView(); 

आप पूरे स्क्रीन जो आपके AlertDialog नीचे है पर कब्जा कर रहे हैं

आप इस पद्धति

करने के लिए अपने संवाद बॉक्स को देखते भेज कर किया जाता अपनी बातें प्राप्त करने के लिए इन तरीकों का उपयोग कर सकते

एक दृश्य

public static Bitmap loadView(View v) { 
    Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888); 
    Canvas c = new Canvas(b); 
    v.layout(0, 0, v.getWidth(), v.getHeight()); 
    v.draw(c); 
    return b; 
} 
से बिटमैप हो जाओ

सहेजा जा रहा है आपका बिटमैप

void saveFile(Bitmap bitmap) { 
    String extr = Environment.getExternalStorageDirectory().toString() + File.separator + "Folder"; 
    String fileName = new SimpleDateFormat("yyyyMMddhhmm'_bitmap.jpg'", Locale.US).format(new Date()); 
    File myPath = new File(extr, fileName); 
    FileOutputStream fos = null; 
    try { 
     fos = new FileOutputStream(myPath); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
     fos.flush(); 
     fos.close(); 
     MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Screen", "screen"); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
+0

मैंने आपके कोड को जो कुछ भी सुझाया है उसे जोड़ने के लिए बदल दिया है, हालांकि मेरे संवाद में मैं विधियों को बुलाता हूं हालांकि वे परिधि मांग रहे हैं, कोई विचार यह होगा कि ये क्या होगा? – Sjharrison

+0

@Sjharrison आप किस प्रकार के पैरामीटर के बारे में बात कर रहे हैं, क्या आप अपना नमूना कोड –

+0

प्रदान कर सकते हैं यदि आप संवाद के लिए ऊपर दिए गए मेरे कोड को देखते हैं तो मैंने मूल रूप से एक नया संवाद 'sendDialogToView();' बनाया है ' जो आपको 'दृश्य से बिटमैप प्राप्त करें' कोड और 'कैप्चरस्क्रीन एंड ओपन();' क्या आपका बैटममैप कोड – Sjharrison

संबंधित मुद्दे