Android GestureLibrary保存且GestureLibrary为只读

Android GestureLibrary保存且GestureLibrary为只读,android,Android,在谷歌搜索了很多次之后,我发布了这个问题 在看了手势生成器的源代码之后,我用它来创建和保存手势。 问题是,我从原始文件加载的手势库加载正确,但当我尝试将新手势保存到它时,它失败了,save方法返回false。 当我选中gestureLibrary.isReadOnly时,它也返回true,这是否意味着我无法保存到它,因为它是只读的? 我正在使用所有权限对外部存储和内部存储进行写入。 有人帮忙吗 当试图保存res文件夹(即res/raw)中的手势文件时,您不能这样做,因为不允许在运行时编辑应用程序

在谷歌搜索了很多次之后,我发布了这个问题 在看了手势生成器的源代码之后,我用它来创建和保存手势。 问题是,我从原始文件加载的手势库加载正确,但当我尝试将新手势保存到它时,它失败了,save方法返回false。 当我选中gestureLibrary.isReadOnly时,它也返回true,这是否意味着我无法保存到它,因为它是只读的? 我正在使用所有权限对外部存储和内部存储进行写入。
有人帮忙吗

当试图保存res文件夹(即res/raw)中的手势文件时,您不能这样做,因为不允许在运行时编辑应用程序资源

因此,您可以将手势文件放置在资源中,然后将其保存在将要安装应用程序的手机中,然后尝试使用GestureLibrary类的save方法保存,这解决了我的问题

将资产文件存储到内部内存的代码:

File gestureFile=new File(directory.getPath(),"gesture");
try {
            InputStream is = getAssets().open("gestures");

            OutputStream os = new FileOutputStream(gestureFile);

            byte[] buffer = new byte[1024];
            int bytesRead;
            //read from is to buffer
            while((bytesRead = is.read(buffer)) !=-1){
                os.write(buffer, 0, bytesRead);
            }
            is.close();
            //flush OutputStream to write any buffered data to file
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
要保存的代码:

mLibrary1=GestureLibraries.fromFile(new File(directory.getPath(),"gesture"));
mLibrary1.addGesture(strTemp,gesture);
            boolean temp= mLibrary1.save();
            if(temp){
                Toast.makeText(getApplicationContext(), "Saved",Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(getApplicationContext(), " Not Saved",Toast.LENGTH_SHORT).show();
            }

很抱歉回复太晚。

在尝试保存res文件夹(即res/raw)中的手势文件时,您不能这样做,因为不允许在运行时编辑应用程序资源

因此,您可以将手势文件放置在资源中,然后将其保存在将要安装应用程序的手机中,然后尝试使用GestureLibrary类的save方法保存,这解决了我的问题

将资产文件存储到内部内存的代码:

File gestureFile=new File(directory.getPath(),"gesture");
try {
            InputStream is = getAssets().open("gestures");

            OutputStream os = new FileOutputStream(gestureFile);

            byte[] buffer = new byte[1024];
            int bytesRead;
            //read from is to buffer
            while((bytesRead = is.read(buffer)) !=-1){
                os.write(buffer, 0, bytesRead);
            }
            is.close();
            //flush OutputStream to write any buffered data to file
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
要保存的代码:

mLibrary1=GestureLibraries.fromFile(new File(directory.getPath(),"gesture"));
mLibrary1.addGesture(strTemp,gesture);
            boolean temp= mLibrary1.save();
            if(temp){
                Toast.makeText(getApplicationContext(), "Saved",Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(getApplicationContext(), " Not Saved",Toast.LENGTH_SHORT).show();
            }

很抱歉回复太晚。

希望下面的答案是修复,是吗?希望下面的答案是修复,是吗?