import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.volcengine.tos.TOSV2;
import com.volcengine.tos.TOSV2ClientBuilder;
import com.volcengine.tos.TosException;
import com.volcengine.tos.model.bucket.ListBucketsV2Input;
import com.volcengine.tos.model.bucket.ListBucketsV2Output;
import com.volcengine.tos.model.bucket.ListedBucket;
public class ListBucketExample extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
String endpoint = "your endpoint";
String region = "your region";
String accessKey = "your access key";
String secretKey = "your secret key";
String securityToken = "your security token";
String bucketName = "your bucket name";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey, securityToken);
Thread tosThread = new Thread(new Runnable() {
ListBucketsV2Input input = new ListBucketsV2Input();
ListBucketsV2Output output = tos.listBuckets(input);
Log.i("listBuckets", "bucket owner is " + output.getOwner());
if (output.getBuckets() != null) {
Log.i("listBuckets", "you have listed " + output.getBuckets().size() + " buckets");
for (int i = 0; i < output.getBuckets().size(); i++){
ListedBucket bucket = output.getBuckets().get(i);
Log.i("listBuckets", "the No." + " bucket is " + bucket.toString());
Log.i("listBuckets", "there are no buckets in your account.");
} catch (TosException e) {
Log.e("TosException", "listBuckets failed");