首先,安裝或選擇 Debian 系統完成後,
(硬碟空間記得要夠,寫這篇文章的時候,10G應該就夠了,但未來不確定)
打開虛擬機:
專攻Android,其他略懂。 奇技淫巧,顧名思義, 泛指作者寫程式時,收集到的有趣寫法,會與不會都無妨。
沒用過AWS 下載,方式蠻多,研究了一陣子,記錄分享。
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String awsAccessKey = "Your-awsAccessKey"; String awsSecretKey = "Your-awsSecretKey"; String sessionToken = "Your-sessionToken"; AWSSessionCredentials awsCred = new BasicSessionCredentials(awsAccessKey , awsSecretKey, sessionToken); String fileKey = "Your-fileKey"; downloadWithTransferUtility(fileKey, awsCred); } private void downloadWithTransferUtility(String fileKey, AWSSessionCredentials awsCred) { TransferNetworkLossHandler.getInstance(getApplicationContext()); AmazonS3Client s3Client = new AmazonS3Client(awsCred, Region.getRegion(Regions.AP_NORTHEAST_1), new ClientConfiguration()); TransferUtility transferUtility = TransferUtility.builder() .context(getApplicationContext()) .awsConfiguration(AWSMobileClient.getInstance().getConfiguration()) .s3Client(s3Client) .defaultBucket("Your-BucketName") .build(); String fileName = getDownloadFileName(fileKey); TransferObserver downloadObserver = transferUtility.download(fileKey, new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + fileName)); // Attach a listener to the observer to get state update and progress notifications downloadObserver.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id, TransferState state) { if (TransferState.COMPLETED == state) { // Handle a completed upload. Toast.makeText(MainActivity.this, "TransferState.COMPLETED", Toast.LENGTH_SHORT).show(); } } @Override public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { float percentDonef = ((float) bytesCurrent / (float) bytesTotal) * 100; int percentDone = (int) percentDonef; Log.d("Your Activity", " ID:" + id + " bytesCurrent: " + bytesCurrent + " bytesTotal: " + bytesTotal + " " + percentDone + "%"); } @Override public void onError(int id, Exception ex) { // Handle errors } }); } public String getDownloadFileName(String key) { String[] path_split = key.split("/"); return path_split[path_split.length - 1]; } }