鸿蒙开源组件——通过文件的Uri获取到文件的path值

jacksky
发布于 2021-11-12 17:22
浏览
0收藏

PickiT

项目介绍

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

效果演示鸿蒙开源组件——通过文件的Uri获取到文件的path值-鸿蒙开发者社区

安装教程

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,如下所示:

@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);

这可以在 onBackPressed 和 onStop 中完成,如下所示:

@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
}

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

 

版本迭代

  • 1.0.0

  • 0.0.1-SNAPSHOT

PickiT-master.zip 496.33K 72次下载
已于2021-11-12 17:22:25修改
3
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
wx62c4f6cff2f31
wx62c4f6cff2f31

Hi,可以帮忙看下这个是什么情况导致的吗?

 

-------

update: 已解决,是build.gradle添加仓库不完整导致

已于2022-7-10 11:01:15修改
回复
2022-7-10 10:45:11
回复
    相关推荐