View Full Version : اسکرین شات
arash.arya43
سه شنبه 02 شهریور 1395, 15:04 عصر
سلام.
ایا میتوان بدون روت کد اسکرین شات نوشت که کار کنه.اگه میشه راهنمایی کنین.اگه میشه ولی نمیخواین پابلیک بشه وهزینه میخواد پیام خصوصی بدین.
msroid
سه شنبه 02 شهریور 1395, 15:08 عصر
سلام
تا جایی که من اطلاع دارم بدون روت شدن نمیشه اینکارو کرد. توی مستندات گوگل هم دلیل اینکار رو حفظ حریم شخصی افراد ذکر کرده. چون اگر هر اپلیکیشنی میتونست واسه خودش به راحتی استکرین شات بگیره دیگه امنیتی برای کاربر باقی نمیموند برای همین این اجازه رو نمیده.
tux-world
سه شنبه 02 شهریور 1395, 19:45 عصر
بستگی داره اسکرین شات رو از کجا بگیری. برنامه خودت یا نه برنامه های دیگه؟
arash.arya43
چهارشنبه 03 شهریور 1395, 13:59 عصر
بستگی داره اسکرین شات رو از کجا بگیری. برنامه خودت یا نه برنامه های دیگه؟
کلا از صفحه نمایش مهندس یعنی یک دگمه میزارم خیلی کوجیک گوشه کاربر لمس کرد از همون صفحه جاری عکس بگیره بدون نیاز به روت .90 درصد گوشیا روت نیستن خوب.
در مورد برنامهای دیگه منظورتون مثلا یک برنامه خاص بازه وفقط از پنجره باز اون یا همون اکتیویتیش میگیره؟.بیشتر توضیح میدین ممنون
در ضمن مهندس ببینین این کدها جواب میده یا سرکاریه
package pl.polidea.asl;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.lang.reflect.Method;import java.net.InetSocketAddress;import java.net.Socket;import java.nio.Buffer;import java.nio.ByteBuffer;import java.nio.channels.SocketChannel;import java.security.InvalidParameterException;import java.util.UUID;import android.app.Service;import android.content.Intent;import android.content.res.Configuration;import android.graphics.Bitmap;import android.graphics.Bitmap.CompressFormat;import android.graphics.Bitmap.Config;import android.graphics.Matrix;import android.os.IBinder;import android.os.RemoteException;import android.util.Log;import android.view.Display;import android.view.Surface;import android.view.WindowManager;public class ScreenshotService extends Service { /* * Action name for intent used to bind to service. */ public static final String BIND = "pl.polidea.asl.ScreenshotService.BIND"; /* * Name of the native process. */ private static final String NATIVE_PROCESS_NAME = "asl-native"; /* * Port number used to communicate with native process. */ private static final int PORT = 42380; /* * Timeout allowed in communication with native process. */ private static final int TIMEOUT = 1000; /* * Directory where screenshots are being saved. */ private static final String SCREENSHOT_FOLDER = "/sdcard/screens/"; /* * An implementation of interface used by clients to take screenshots. */ private final IScreenshotProvider.Stub mBinder = new IScreenshotProvider.Stub() { public String takeScreenshot() throws RemoteException { try { return ScreenshotService.this.takeScreenshot(); } catch (Exception e) { return null; } } public boolean isAvailable() throws RemoteException { return isNativeRunning(); } }; @Override public void onCreate() { Log.i("service", "Service created."); } @Override public IBinder onBind(Intent intent) { return mBinder; } /* * Checks whether the internal native application is running, */ private boolean isNativeRunning() { try { Socket sock = new Socket(); sock.connect(new InetSocketAddress("localhost", PORT), 10); // short // timeout } catch (Exception e) { return false; } return true; // ActivityManager am = // (ActivityManager)getSystemService(Service.ACTIVITY _SERVICE); // List<ActivityManager.RunningAppProcessInfo> ps = // am.getRunningAppProcesses(); // // if (am != null) { // for (ActivityManager.RunningAppProcessInfo rapi : ps) { // if (rapi.processName.contains(NATIVE_PROCESS_NAME)) // // native application found // return true; // } // // } // return false; } /* * Internal class describing a screenshot. */ static final class Screenshot { public Buffer pixels; public int width; public int height; public int bpp; public boolean isValid() { if (pixels == null || pixels.capacity() == 0 || pixels.limit() == 0) return false; if (width <= 0 || height <= 0) return false; return true; } } /* * Determines whether the phone's screen is rotated. */ private int getScreenRotation() { WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); // check whether we operate under Android 2.2 or later try { Class<?> displayClass = disp.getClass(); Method getRotation = displayClass.getMethod("getRotation"); int rot = ((Integer) getRotation.invoke(disp)).intValue(); switch (rot) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; default: return 0; } } catch (NoSuchMethodException e) { // no getRotation() method -- fall back to getOrientation() int orientation = disp.getOrientation(); // Sometimes you may get undefined orientation Value is 0 // simple logic solves the problem compare the screen // X,Y Co-ordinates and determine the Orientation in such cases if (orientation == Configuration.ORIENTATION_UNDEFINED) { Configuration config = getResources().getConfiguration(); orientation = config.orientation; if (orientation == Configuration.ORIENTATION_UNDEFINED) { // if height and widht of screen are equal then // it is square orientation if (disp.getWidth() == disp.getHeight()) { orientation = Configuration.ORIENTATION_SQUARE; } else { // if widht is less than height than it is portrait if (disp.getWidth() < disp.getHeight()) { orientation = Configuration.ORIENTATION_PORTRAIT; } else { // if it is not any of the above it will // defineitly be landscape orientation = Configuration.ORIENTATION_LANDSCAPE; } } } } return orientation == 1 ? 0 : 90; // 1 for portrait, 2 for landscape } catch (Exception e) { return 0; // bad, I know ;P } } /* * Communicates with the native service and retrieves a screenshot from it * as a 2D array of bytes. */ private Screenshot retreiveRawScreenshot() throws Exception { try { // connect to native application // We use SocketChannel,because is more convenience and fast SocketChannel socket = SocketChannel.open(new InetSocketAddress( "localhost", PORT)); socket.configureBlocking(false); // Send Commd to take screenshot ByteBuffer cmdBuffer = ByteBuffer.wrap("SCREEN".getBytes("ASCII")); socket.write(cmdBuffer); // build a buffer to save the info of screenshot // 3 parts,width height cpp byte[] info = new byte[3 + 3 + 2 + 2];// 3 bytes width + 1 byte // space + 3 bytes heigh + 1 // byte space + 2 bytes bpp ByteBuffer infoBuffer = ByteBuffer.wrap(info); // we must make sure all the data have been read while (infoBuffer.position() != infoBuffer.limit()) socket.read(infoBuffer); // we must read one more byte,because after this byte,we will read // the image byte socket.read(ByteBuffer.wrap(new byte[1])); // set the position to zero that we can read it. infoBuffer.position(0); StringBuffer sb = new StringBuffer(); for (int i = 0; i < (3 + 3 + 2 + 2); i++) { sb.append((char) infoBuffer.get()); } String[] screenData = sb.toString().split(" "); if (screenData.length >= 3) { Screenshot ss = new Screenshot(); ss.width = Integer.parseInt(screenData[0]); ss.height = Integer.parseInt(screenData[1]); ss.bpp = Integer.parseInt(screenData[2]); // retreive the screenshot // (this method - via ByteBuffer - seems to be the fastest) ByteBuffer bytes = ByteBuffer.allocate(ss.width * ss.height * ss.bpp / 8); while (bytes.position() != bytes.limit()) { // in the cycle,we must make sure all the image data have // been read,maybe sometime the socket will delay a bit time // and return some invalid bytes. socket.read(bytes); // reading all at once for speed } bytes.position(0); // reset position to the beginning of // ByteBuffer ss.pixels = bytes; return ss; } } catch (Exception e) { throw new Exception(e); } finally { } return null; } /* * Saves given array of bytes into image file in the PNG format. */ private void writeImageFile(Screenshot ss, String file) { if (ss == null || !ss.isValid()) throw new IllegalArgumentException(); if (file == null || file.length() == 0) throw new IllegalArgumentException(); // resolve screenshot's BPP to actual bitmap pixel format Bitmap.Config pf; switch (ss.bpp) { case 16: pf = Config.RGB_565; break; case 32: pf = Config.ARGB_8888; break; default: pf = Config.ARGB_8888; break; } // create appropriate bitmap and fill it wit data Bitmap bmp = Bitmap.createBitmap(ss.width, ss.height, pf); bmp.copyPixelsFromBuffer(ss.pixels); // handle the screen rotation int rot = getScreenRotation(); if (rot != 0) { Matrix matrix = new Matrix(); matrix.postRotate(-rot); bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); } // save it in PNG format FileOutputStream fos; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { throw new InvalidParameterException(); } bmp.compress(CompressFormat.PNG, 100, fos); } /* * Takes screenshot and saves to a file. */ private String takeScreenshot() throws IOException { // make sure the path to save screens exists File screensPath = new File(SCREENSHOT_FOLDER); if (!screensPath.exists()) screensPath.mkdir(); // construct screenshot file name StringBuilder sb = new StringBuilder(); sb.append(SCREENSHOT_FOLDER); sb.append(Integer.toHexString(UUID.randomUUID().ha shCode())); // hash // code // of // UUID // should // be // quite // random // yet // short sb.append(".png"); String file = sb.toString(); // fetch the screen and save it Screenshot ss = null; try { ss = retreiveRawScreenshot(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } writeImageFile(ss, file); return file; }}
arash.arya43
چهارشنبه 03 شهریور 1395, 14:35 عصر
ضمیمه شد...
arash.arya43
پنج شنبه 04 شهریور 1395, 11:44 صبح
دوستان راهنمایی کنین مطمعنا میشه چون تو نت همنرمافزار اسکرین شات بدون روت هست پس شدنیه
spiderman200700
پنج شنبه 04 شهریور 1395, 13:42 عصر
فکر میکنم بدون روت فقط از محیط برنامه خودت میتونی تصویر قابل ذخیره بسازی. از هر جایی نمیتونی.
البته یه لایبراری به اسم android-screenshot-library (http://code.google.com/p/android-screenshot-library/) هست که اجازه این کار رو توی بعضی گوشی ها بهت میده که این لایبراری هم از اندروید 5 به بعد دیگه جواب نمیده.
کلا بدون روت فکر نمیکنم بتونی موفق بشی
arash.arya43
پنج شنبه 04 شهریور 1395, 14:09 عصر
android-screenshot-library این رو شنیدم به اضافه اینکه بوسیله کی ایونت ها هم میشه در ضمن تو نت نرم افزار اسکرین شات بدون روت هست که هفته پیش تست کردم کار میکنه پس میشه.و در اخر برای نسخه4 هم راضیم فقط ببینیم چه طوریاست
spiderman200700
پنج شنبه 04 شهریور 1395, 14:23 عصر
خب همین android-screenshot-library رو بررسی کن ببین به دردت میخوره یا نه
arash.arya43
پنج شنبه 04 شهریور 1395, 14:26 عصر
خوب میشه یک سورس پیشنهاد بدین من تازه دارم جاوا مطالعه میکنم که وارد اکلیپس بشم:ناراحت:
spiderman200700
پنج شنبه 04 شهریور 1395, 14:32 عصر
کتابخانه android-screenshot-library رو دانلود کن.
اینم یه نمونه کد:
import pl.polidea.asl.*;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources.NotFoundException;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.*;
public class ScreenshotDemo extends Activity {
// The ImageView used to display taken screenshots.
private ImageView imgScreen;
private ServiceConnection aslServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
aslProvider = IScreenshotProvider.Stub.asInterface(service);
}
};
private IScreenshotProvider aslProvider = null;
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgScreen = (ImageView)findViewById(R.id.imgScreen);
Button btn = (Button)findViewById(R.id.btnTakeScreenshot);
btn.setOnClickListener(btnTakeScreenshot_onClick);
// connect to ASL service
//Intent intent = new Intent(ScreenshotService.class.getName());
Intent intent = new Intent();
intent.setClass(this, ScreenshotService.class);
//intent.addCategory(Intent.ACTION_DEFAULT);
bindService (intent, aslServiceConn, Context.BIND_AUTO_CREATE);
}
@Override
public void onDestroy() {
unbindService(aslServiceConn);
super.onDestroy();
}
private View.OnClickListener btnTakeScreenshot_onClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (aslProvider == null)
Toast.makeText(ScreenshotDemo.this, R.string.n_a, Toast.LENGTH_SHORT).show();
else if (!aslProvider.isAvailable())
Toast.makeText(ScreenshotDemo.this, R.string.native_n_a, Toast.LENGTH_SHORT).show();
else {
String file = aslProvider.takeScreenshot();
if (file == null)
Toast.makeText(ScreenshotDemo.this, R.string.screenshot_error, Toast.LENGTH_SHORT).show();
else {
Toast.makeText(ScreenshotDemo.this, R.string.screenshot_ok, Toast.LENGTH_SHORT).show();
Bitmap screen = BitmapFactory.decodeFile(file);
imgScreen.setImageBitmap(screen);
}
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// squelch
}
}
};
}
arash.arya43
پنج شنبه 04 شهریور 1395, 14:33 عصر
مرسی برم بررسی کنم نتیجه روهمین جا اعلام میکنم.فعلا روزخوش
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.