takix
Verdiğiniz Java ve XML kodlarında bazı hatalar ve güncellemeler yapılması gerekiyor. İşte düzeltilmiş ve güncellenmiş kodlar:
Düzeltilmiş Java Class Kodu:
`public Uri getLocalBitmapUri() {
LinearLayout linearLayout = findViewById(R.id.parent); /Your root view to be part of screenshot/
linearLayout.setDrawingCacheEnabled(true);
linearLayout.buildDrawingCache();
Bitmap bmp = linearLayout.getDrawingCache();
// Store image to default external storage directory
Uri bmpUri = null;
File file;
try {
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + getString(R.string.app_name) + "/");
dir.mkdirs();
String fileName = System.currentTimeMillis() + "_share_image.png";
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
file = new File(dir, fileName);
} else {
file = new File(dir.getPath(), fileName);
}
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file);
} catch (IOException e) {
e.printStackTrace();
}
linearLayout.setDrawingCacheEnabled(false);
return bmpUri;
}
`
Düzeltilmiş XML Kodu:
`<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:layoutDirection="ltr"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- Rest of your XML layout code goes here -->
</androidx.constraintlayout.widget.ConstraintLayout>
`
Yukarıda düzeltilmiş ve güncellenmiş kodları eklerken dikkatli olunmalıdırç. Ancak, tam olarak işlevselliği ve diğer gereksinimleri anlamak için mevcut kodunuzun tamamını görmek önemlidir. Bu nedenle, yukarıdaki düzeltmeleri mevcut kodunuza entegre ederken dikkate almanız önemlidir.