build.gradle file at the project level (usually in the root directory):repositories {google()// add this linemavenCentral()}
build.gradle file at the app-level (usually in the app module):dependencies {...// add this lineimplementation 'com.qcloud.cos:smh-android:1.2.37'}
build.gradle file at the app-level (usually in the app module) to:dependencies {...change toimplementation 'com.qcloud.cos:smh-android-nobeacon:1.2.37'}
AndroidManifest.xml file under the application module:<uses-permission android:name="android.permission.INTERNET"/>
AndroidManifest.xml file under the application module:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
SMHSimpleUser to retrieve the libraryId and userSpace, request an access token, and return the result.class MySMHSimpleUser: SMHSimpleUser() {override val libraryId: Stringget() = "smh3ptyc9mscifdi"override val userSpace: UserSpaceget() = UserSpace(userId = "7",spaceId = "space1x8mfjgno6nyy")override suspend fun provideAccessToken(): AccessToken {// First, get the response containing access token information from your access token server// Then parse the response to get the access token infoString token = "token"; // Access tokenlong expiresIn = 86400;// access token valid duration, in seconds// Recommend using server time as the signature start time to avoid request expiration due to excessive deviation in user's mobile local time// Use server time as the signature start timelong startTime = 1556182000L; // access token start timestamp, in ms// Finally return the access token info objectreturn new AccessToken(token, startTime, expiresIn);}}
MySMHSimpleUser. Initialize an instance to provide the access token to the SDK.val mySMHSimpleUser: MySMHSimpleUser = MySMHSimpleUser();
mySMHSimpleUser with your provided key to initialize an instance of SMHCollection.SMHCollection provides access to all APIs for SMH. In follow-up documentation, SMH refers to the created SMHCollection instance.
Initialize SMHCollection, get instanceval smh: SMHCollection = SMHCollection(context = context,user = mySMHSimpleUser,// Assign the "Access domain" displayed after creating a media library through the console to customHostcustomHost = "<libraryId>.api.tencentsmh.cn")
//target folderval targetDir = Directory()try {val directoryContents: DirectoryContents = smh.list(//target directorydir = targetDir,//page numberpage = 1,//Items per PagepageSize = 100,//Sorting methodorderType = OrderType.NAME,//Sorting orderorderDirection = OrderDirection.ASC,//Filter typedirectoryFilter = DirectoryFilter.ONLY_FILE)//File/directory list. Check the DirectoryContents entity for other numbers etc.val contents = directoryContents.contents} catch (e: Exception) {e.printStackTrace()}
Feedback