(۱۳۹۴/۱۰/۱۵, ۱۰:۴۱ ب.ظ)osam نوشته: سلام دوستان ،
کسی میدونه چجوری از گوشی بدون روت، اسکرین شات گرفت ،
معرفی برنامه نمی خوام منظورم کد هستش
اگه کسی میدونه لطفا راهنمایی کنید؟
سلام خدمت دوست عزیزم.
امیدوارم اموزشی که میدم بتونه کمکتون کنه.
ابتدا توی کلاس مورد نظر کد زیر رو تعریف کنید.
کد پیاچپی:
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();
}
}
خب حالا توی ماینفست دسترسی رو براش تعریف کنید.
کد پیاچپی:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
حالا برای اینکه بتونید عکس های گرفته شده رو توسط یک intent مشاهده کنید از کد زیر استفاده کنید.
کد پیاچپی:
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);
}
این اموزش برگفته شده از سایت
stackoverflow.com میباشد.
با ارزوی موفقیت برای شما.
***خطا و مشکلات در برنامه نویسی پایه موفقیت است و به وسیله ی آن می توان به موفقیت رسید.***