代码拉取完成,页面将自动刷新
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);
这可以在 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
}
如果您在实现库时遇到任何问题,请查看演示项目.
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
1.0.0
0.0.1-SNAPSHOT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型