6 Star 0 Fork 1

CHINASOFT3_OHOS / PickiT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

PickiT

项目介绍

  • 项目名称:该库可通过文件的Uri获取到文件的path值
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:该库可通过文件的Uri获取到文件的path功能
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio2.2 beta1
  • 基线版本: Release 0.1.14

效果演示

效果演示

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
   repositories {
       maven {
           url 'https://s01.oss.sonatype.org/content/repositories/releases/'
       }
   }
}

2.在entry模块的build.gradle文件中,

dependencies {
   implementation('com.gitee.chinasoft_ohos:PickiT:1.0.0')
   ......  
}

在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

首先,实现PickiT回调,如下所示:

public class MainAbilitySlice extends AbilitySlice implements PickiTCallbacks {

Alt+Enter 为了实现这些方法,我们将在自述文件的后面部分讨论这些方法.

onStart()方法中实现pickiT,如下所示:

public class MainAbilitySlice extends AbilitySlice implements PickiTCallbacks {
    //Declare PickiT
    PickiT pickiT;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        //Initialize PickiT
        //context, listener, AbilitySlice
        pickiT = new PickiT(this, this, this);

    }
}

现在您可以像平常一样选择一个文件(如果您不知道如何做,请看演示).

然后在onAbilityResult中,可以将路径传递给PickiT,如下所示:

@Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);
        if (requestCode == SELECT_VIDEO_REQUEST) {
            if (resultCode == RESULT_OK && resultData.getUri() != null) {
                pickiT.getPath(resultData.getUri());
                originalText.setText(String.valueOf(resultData.getUri()));
            }
        }
    }

在处理完文件后通过调用:

pickiT.deleteTemporaryFile(Context);

这可以在 onBackPressedonStop 中完成,如下所示:

@Override
protected void onBackPressed() {
    pickiT.deleteTemporaryFile(this);
    super.onBackPressed();
}

 @Override
 protected void onStop() {
    super.onStop();
    if (!isChangingConfigurations()) {
        pickiT.deleteTemporaryFile(this);
    }
}

如果不调用 pickiT.deleteTemporaryFile(Context);, 该文件将保留在上述文件夹中,并且每次选择新文件时都会被覆盖.

回调方法

//When selecting a file from Drive, for example, the Uri will be returned before the file is available(if it has not yet been cached/downloaded).
//We are unable to see the progress
//Apps like Dropbox will display a dialog inside the picker
//This will only be called when selecting a drive file
@Override
public void PickiTonUriReturned() {
    //Use to let user know that we are waiting for the application to return the file
    //See the demo project to see how I used this.
}

//Called when the file creations starts (similar to onPreExecute)
//This will only be called if the selected file is not local or if the file is from an unknown file provider
@Override
public void PickiTonStartListener() {
    //Can be used to display a ProgressDialog
}

//Returns the progress of the file being created (in percentage)
//This will only be called if the selected file is not local or if the file is from an unknown file provider
@Override
public void PickiTonProgressUpdate(int progress) {
    //Can be used to update the progress of your dialog
}

//If the selected file was a local file then this will be called directly, returning the path as a String.
//String path - returned path
//boolean wasDriveFile - check if it was a drive file
//boolean wasUnknownProvider - check if it was from an unknown file provider
//boolean wasSuccessful - check if it was successful
//String reason - the get the reason why wasSuccessful returned false
@Override
public void PickiTonCompleteListener(String path, boolean wasDriveFile, boolean wasUnknownProvider, boolean wasSuccessful, String reason) {
    //Dismiss dialog and return the path
}

如果您在实现库时遇到任何问题,请查看演示项目.

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.0

  • 0.0.1-SNAPSHOT

MIT License Copyright (c) [2020] [HBiSoft] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

该库可通过文件的Uri获取到文件的path功能 展开 收起
Java
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/chinasoft3_ohos/PickiT.git
git@gitee.com:chinasoft3_ohos/PickiT.git
chinasoft3_ohos
PickiT
PickiT
master

搜索帮助