2014-03-12 5 views
1

중립 버튼을 클릭하면 알림 대화 상자의 이미지가 sdcard에 저장되는 앱을 디자인해야합니다. 그래서 프로그램 적으로 스크린 샷을 찍은 다음 BitmapDecodeRegion 클래스를 사용하여 이미지를 자르기로 결정했습니다.스크린 샷의 알림 대화 상자 표시

그러나 스크린 샷을 찍을 때 창에 첨부되어 있지 않으므로 경고 대화 상자에 나타나지 않습니다. 어떻게 창에 붙일 수 있습니까?

public void btnClick(View v) { 
    Log.d("", "logger button clicked"); 
    AlertDialog.Builder dialog = new AlertDialog.Builder(this); 
    dialog.setTitle("This is a demo!"); 
    dialog.setMessage("Lets see if this works"); 
    dialog.setCancelable(false); 
    dialog.setNeutralButton("Take Snap", 
      new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 

        Bitmap bitmap; 
        View v1 = findViewById(android.R.id.content) 
          .getRootView(); 
        v1.setDrawingCacheEnabled(true); 
        bitmap = Bitmap.createBitmap(v1.getDrawingCache()); 
        GlobalObj.screenImg = bitmap; 
        v1.setDrawingCacheEnabled(false); 

        Intent i = new Intent(MainActivity.this, 
          ViewActivity.class); 
        startActivity(i); 

       } 
      }); 

    AlertDialog newDialog = dialog.create(); 
    newDialog.show(); 

이 친절하게 도와 : 여기

는 코드입니다.

+0

다음 링크를 확인하십시오. http://stackoverflow.com/questions/20136121/android-how-to-take-screenshot-programatically – Priya

답변

0

https://github.com/jraska/Falcon이 라이브러리를 사용해보세요. 대화 상자를 포함하여 모든 활성 창에 대한 스크린 샷이 표시되어 문제를 파악할 수 있습니다. 코드 변경에

0

이 라인이에

View v1 = findViewById(android.R.id.content) 
         .getRootView(); 

: 그것은 나를 위해 작동과 뿌리 전화를 필요로하지 않는다

View v1 = AlertDialog.class.cast(dialog).getWindow().getDecorView().getRootView(); 

. 그러나 이것은 활동의 기본보기없이 검은 색 배경의 경고 대화 상자 만 캡처합니다. 모든 것을 갖고 싶다면 (간단하지 않은) Aswin Rajendiran의 this answer을 시도해보십시오.

관련 문제