Skip to content

Commit

Permalink
Update the version of storage to 1.3.1.200
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindixia committed Jun 9, 2021
1 parent 9a7cabe commit c7bc00d
Show file tree
Hide file tree
Showing 71 changed files with 933 additions and 187 deletions.
2 changes: 2 additions & 0 deletions cloudstorage/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
/build
/captures
.externalNativeBuild
.cxx
local.properties
49 changes: 39 additions & 10 deletions cloudstorage/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# NearbyMessageDemo-AGCCloudStorageAndroidSDK
# CloudStorage quickstart

English | [中文](./README_ZH.md)

## Contents
* [Introduction](#introduction)
* [Supported Environments](#supported-environments)
* [Procedure](#procedure)
* [Preparing the Environments](#Preparing the Environments)
* [Getting Started](#Getting Started)
* [Sample Code](#Sample Code)
* [Question or issues](#question-or-issues)
* [License](#License)

## Introduction
This demo demonstrates an example of using the SDK to store pictures, videos, audio, or other user-generated files. For details about the SDK, please refer to https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started.

Getting Started
For more development details, please refer to the following link:
Development Guide: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started
API References: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-References/cloudstroage

## Procedure
## Preparing the Environments
* A computer with Android Studio installed for app development
* A device or emulator in Android Studio running Android 4.2 or a later version

## Getting Started

Before running the quickstart app, you need to:

1. Activate cloud storage service: The cloud storage service is not activated by default. You need to manually activate the cloud storage service in AGC.

2. New storage instance: After opening the cloud storage service, AGC will automatically create a default storage instance. If you want to store application system data and user data separately, you can create a new storage instance yourself.
Expand All @@ -23,7 +32,27 @@ API References: https://developer.huawei.com/consumer/cn/doc/development/AppGall

5. File management: The application client can call the API of the cloud storage SDK to perform operations such as uploading files, downloading files, deleting files, and modifying file metadata.

## Supported Environments
Android Studio 3.0 or a later version is recommended.

For more development details, please refer to the following link:
Development Guide: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started

API References: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-References/cloudstroage

## Sample Code

Sample code: /app/src/main/java/com/huawei/agc/quickstart/storage/MainActivity.java

Kotlin Sample code: /kotlin-app/src/main/java/com/huawei/agconnect/kotlindemo/MainActivityKotlin.kt


## Question or issues
If you have questions about how to use AppGallery Connect Demos, try the following options:
* [Stack Overflow](https://stackoverflow.com/users/14194729/appgallery-connect) is the best place for any programming questions. Be sure to tag your question with appgallery.
* [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/home?fid=0101188387844930001) AppGallery Module is great for general questions, or seeking recommendations and opinions.

If you run into a bug in our samples, please submit an [issue](https://github.com/AppGalleryConnect/agc-demos/issues) to the Repository. Even better you can submit a [Pull Request](https://github.com/AppGalleryConnect/agc-demos/pulls) with a fix.

## License
quickstart is licensed under the [Apache License, version 2.0] (http://www.apache.org/licenses/LICENSE-2.0).


63 changes: 63 additions & 0 deletions cloudstorage/README_ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# CloudStorage quickstart

中文 | [English](./README.md)

## 目录

- [简介](#简介)
- [环境要求](#环境要求)
- [快速入门](#快速入门)
- [示例代码](#示例代码)
- [技术支持](#技术支持)
- [授权许可](#授权许可)

## 简介

本Demo演示了使用SDK存储图片、视频、音频或其他用户生成的文件的示例。

有关SDK的详细信息,请参见: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started

## 环境要求

* 在使用quickstart 之前,开发者需要配置好Android开发环境
* 一台Android设备或者模拟器,需要支持Android 4.2及以上版本

## 快速入门

在运行quickstart前,您需要

1、激活云存储服务:默认不激活云存储服务。您需要在AGC中手动激活云存储服务。

2、新存储实例:打开云存储服务后,AGC将自动创建默认存储实例。如果您希望将应用系统数据和用户数据分开存储,您可以自行创建新的存储实例。

3、集成SDK:如果您需要在应用客户端中使用云存储相关功能,则必须集成云存储客户端SDK。

4、初始化云存储:在应用客户端使用云存储之前,需要初始化云存储,并指定客户端使用的存储实例。

5、文件管理:应用客户端可以调用云存储SDK的API,进行上传文件、下载文件、删除文件、修改文件元数据等操作。

有关更多开发详细信息,请参阅以下链接:
开发指南:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started

API参考:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-References/cloudstroage

## 代码

Sample code: /app/src/main/java/com/huawei/agc/quickstart/storage/MainActivity.java

Kotlin Sample code: /kotlin-app/src/main/java/com/huawei/agconnect/kotlindemo/MainActivityKotlin.kt



## 技术支持

如果您对使用AppGallery Connect示例代码有疑问,请尝试:

- 开发过程遇到问题上[Stack Overflow](https://stackoverflow.com/users/14194729/appgallery-connect),在`appgallery`标签下提问,有华为研发专家在线一对一解决您的问题。
-[华为开发者论坛](https://developer.huawei.com/consumer/cn/forum/blockdisplay?fid=18) AppGallery Connect板块与其他开发者进行交流。

如果您在尝试示例代码中遇到问题,请向仓库提交[issue](https://github.com/AppGalleryConnect/agc-demos/issues),也欢迎您提交[Pull Request](https://github.com/AppGalleryConnect/agc-demos/pulls)

## 授权许可

该示例代码经过[Apache 2.0 授权许可](http://www.apache.org/licenses/LICENSE-2.0)
1 change: 1 addition & 0 deletions cloudstorage/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions cloudstorage/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "Replace the app package name with your own app package name on AppGallery Connect (AGC)."
minSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//agconnect-storage
implementation 'com.huawei.agconnect:agconnect-storage:1.3.1.200'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.agconnect.cloud.storage.demo">
package="com.huawei.agc.quickstart.storage">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

android:theme="@style/Theme.Storage">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.huawei.agconnect.cloud.storage.demo;
package com.huawei.agc.quickstart.storage;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.huawei.agconnect.AGCRoutePolicy;
import com.huawei.agconnect.AGConnectInstance;
import com.huawei.agconnect.AGConnectOptions;
import com.huawei.agconnect.AGConnectOptionsBuilder;
import com.huawei.agconnect.auth.AGConnectAuth;
import com.huawei.agconnect.cloud.storage.core.AGCStorageManagement;
import com.huawei.agconnect.cloud.storage.core.DownloadTask;
Expand All @@ -19,8 +23,11 @@
import com.huawei.hmf.tasks.Task;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class MainActivity extends AppCompatActivity {

private AGCStorageManagement mAGCStorageManagement;
private TextView mShowResultTv;
private String[] permissions = {
Expand All @@ -39,16 +46,31 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initAGCStorageManagement() {
mAGCStorageManagement = AGCStorageManagement.getInstance();
mAGCStorageManagement = AGCStorageManagement.getInstance("Bucket Name");
mShowResultTv.setText("initAGCStorageManagement success! ");
}

private void initChinaAGCStorageManagement() {
AGConnectOptions cnOptions = new AGConnectOptionsBuilder().setRoutePolicy(AGCRoutePolicy.CHINA).build(this);
AGConnectInstance cnInstance = AGConnectInstance.buildInstance(cnOptions);
mAGCStorageManagement = AGCStorageManagement.getInstance(cnInstance, "Bucket Name");
}

private void login() {
if (AGConnectAuth.getInstance().getCurrentUser() != null) {
System.out.println("already sign a user");
return;
}
AGConnectAuth.getInstance().signInAnonymously().addOnSuccessListener(signInResult -> System.out.println("AGConnect OnSuccess"))
.addOnFailureListener(e -> System.out.println("AGConnect OnFail: " + e.getMessage()));
AGConnectAuth.getInstance().signInAnonymously()
.addOnSuccessListener(signInResult -> {
System.out.println("AGConnect OnSuccess");
}).addOnFailureListener(e -> {
System.out.println("AGConnect OnFail: " + e.getMessage());
});
}

public void initAGCStorageManagement(View view) {
initAGCStorageManagement();
}

public void uploadFile(View view) {
Expand Down Expand Up @@ -98,12 +120,12 @@ private void deleteFile() {
System.out.println(String.format("path=%s", path));
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
Task<Void> deleteTask = storageReference.delete();
try {
deleteTask.addOnSuccessListener(aVoid -> mShowResultTv.setText("delete success!"))
.addOnFailureListener(e -> mShowResultTv.setText("delete failure!"));
} catch (Exception e) {
e.printStackTrace();
}

deleteTask.addOnSuccessListener(aVoid -> {
mShowResultTv.setText("delete success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("delete failure! " + e.getMessage());
});
}

private void uploadFile() {
Expand All @@ -117,12 +139,12 @@ private void uploadFile() {
}
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
UploadTask uploadTask = storageReference.putFile(file);
try {
uploadTask.addOnSuccessListener(uploadResult -> mShowResultTv.setText("upload success!"))
.addOnFailureListener(e -> mShowResultTv.setText("upload failure!"));
} catch (Exception e) {
e.printStackTrace();
}

uploadTask.addOnSuccessListener(uploadResult -> {
mShowResultTv.setText("upload success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("upload failure! " + e.getMessage());
});
}

private void downloadFile() {
Expand All @@ -132,50 +154,50 @@ private void downloadFile() {
final File file = new File(agcSdkDirPath, fileName);
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
DownloadTask downloadTask = storageReference.getFile(file);
try {
downloadTask.addOnSuccessListener(downloadResult -> mShowResultTv.setText("download success!"))
.addOnFailureListener(e -> mShowResultTv.setText("download failure!"));
} catch (Exception e) {
e.printStackTrace();
}

downloadTask.addOnSuccessListener(downloadResult -> {
mShowResultTv.setText("download success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("download failure! " + e.getMessage());
});
}

private void getFileMetadata() {
final String path = "test.jpg";
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
Task<FileMetadata> fileMetadataTask = storageReference.getFileMetadata();
try {
fileMetadataTask.addOnSuccessListener(metadata -> mShowResultTv.setText("getfilemetadata success!"))
.addOnFailureListener(e -> mShowResultTv.setText("getfilemetadata failure!"));
} catch (Exception e) {
e.printStackTrace();
}

fileMetadataTask.addOnSuccessListener(fileMetadata -> {
mShowResultTv.setText("getfilemetadata success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("getfilemetadata failure! " + e.getMessage());
});
}

private void updateFileMetadata() {
final String path = "test.jpg";
FileMetadata fileMetadata = initFileMetadata();
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
Task<FileMetadata> fileMetadataTask = storageReference.updateFileMetadata(fileMetadata);
try {
fileMetadataTask.addOnSuccessListener(metadata -> mShowResultTv.setText("updatefilemetadata success!"))
.addOnFailureListener(e -> mShowResultTv.setText("updatefilemetadata failure!"));
} catch (Exception e) {
e.printStackTrace();
}

fileMetadataTask.addOnSuccessListener(fileMetadata1 -> {
mShowResultTv.setText("updatefilemetadata success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("updatefilemetadata failure! " + e.getMessage());
});
}

private void getFileList() {
final String path = "test.jpg";
StorageReference storageReference = mAGCStorageManagement.getStorageReference(path);
Task<ListResult> listResultTask = null;
listResultTask = storageReference.list(100);
try {
listResultTask.addOnSuccessListener(listResult -> mShowResultTv.setText("getfilelist success!"))
.addOnFailureListener(e -> mShowResultTv.setText("getfilelist failure!"));
} catch (Exception e) {
e.printStackTrace();
}

listResultTask.addOnSuccessListener(listResult -> {
mShowResultTv.setText("getfilelist success!");
}).addOnFailureListener(e -> {
mShowResultTv.setText("getfilelist failure! " + e.getMessage());
});
}

private FileMetadata initFileMetadata() {
Expand Down
Loading

0 comments on commit c7bc00d

Please sign in to comment.