我近几年编程到Android,我想知道:如何检测用户何时截屏?我希望当用户截取屏幕截图时,我们会转到下一个活动.我尝试了拦截事件的方法,但是存在一个问题:例如,当设备进入休眠状态时,拦截了一个事件.您是否有拦截仅截取事件或忽略其他事件的解决方案?
谢谢您的帮助 !
我正在尝试从我的Environment.getExternalStorageDirectory()加载屏幕截图并尝试将其转换为位图
public void onPictureTaken(String path) throws IOException {
String photoPath = filepath + "/" + path;; //UPDATE WITH YOUR OWN JPG FILE
File directory = new File (filepath);
File file = new File(directory, path);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, options);
// Calculate inSampleSize
options.inSampleSize = 4;
options.inJustDecodeBounds = false;
BitmapFactory.decodeFile(photoPath, options);
}
Run Code Online (Sandbox Code Playgroud)
--- SkImageDecoder :: Factory返回null
这是我调用onPictureTaken的函数:
private void observeSceenshot(){
filepath = Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_PICTURES
+ File.separator + "Screenshots";
Log.d(TAG, filepath);
FileObserver fileObserver …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我想检测目录中的事件.这是代码:
String path = Environment.getExternalStorageDirectory()
+ File.separator + "test2";
Log.d("test", "path is " + path);
FileObserver fileObserver = new FileObserver(path, FileObserver.ALL_EVENTS) {
@Override
public void onEvent(int event, String path) {
Log.d("test", "event dectect " + event + " " + path);
}
};
fileObserver.startWatching();
Run Code Online (Sandbox Code Playgroud)
我将新文件复制到该目录.但我没有得到任何事件.请告诉我我犯了什么错误.