2017-04-26 9 views
1

これは私のコードです。同じ古いスクリーンショットを共有しています。古いスクリーンショットを削除して新しいスクリーンショットを生成するにはどうすればよいですか?また、Facebookで共有している間は、私が提供したリンクは追加されません。それは、うまく働いているwhatsappのfacebook上のスクリーンショットだけを共有するが、同じ古い絵を共有する。新しいスクリーンショットを生成する

public Bitmap takeScreenshot() { 
     View rootView = findViewById(android.R.id.content).getRootView(); 
     rootView.setDrawingCacheEnabled(true); 
     return rootView.getDrawingCache(); 
} 

public void saveBitmap(Bitmap bitmap) { 
    imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png"); 
    FileOutputStream fos; 
    try { 
     fos = new FileOutputStream(imagePath); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); 
     fos.flush(); 
     fos.close(); 
    } catch (IOException e) { 
     Log.e("GREC", e.getMessage(), e); 
    }} 
private void shareIt() { 

    Uri uri = Uri.fromFile(imagePath); 
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
    sharingIntent.setType("image/*"); 
    String shareBody = "Can you solve this , I am stuck/n try your answer at www.shackless.shan.com"; 

    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); 
    sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); 

    startActivity(Intent.createChooser(sharingIntent, "Challenge via")); 
} 
public void shareOnWhatsapp(View view) { 
    Bitmap bitmap = takeScreenshot(); 
    saveBitmap(bitmap); 
    shareIt(); 
} 

答えて

0

私は描画キャッシュをinValidateする必要があります。 view.invalidate()を使用します。 befre setDrawingCacheEnabled(true)。

public Bitmap takeScreenshot() { 
     View rootView = findViewById(android.R.id.content).getRootView(); 

     rootView.invalidate(); 
     rootView.setDrawingCacheEnabled(true); 
     return rootView.getDrawingCache(); 
    } 
関連する問題