Android Studio ```kotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.Button import android.widget.EditText import android.widget.Toast class MainActivity : AppCompatActivity() { override fun onCreate(s视频edInstanceState: Bundle?) { super.onCreate(s影音edInstanceState) setContentView(R.layout.activity_main) val downloadButton = findViewById(R.id.download_button) val urlEditText = findViewById(R.id.url_edit_text) downloadButton.setOnClickListener(View.OnClickListener { val url = urlEditText.text.toString() // Start a download task DownloadTask(this).execute(url) }) } // AsyncTask to download the file private class DownloadTask internal constructor(context: Context) : AsyncTask() { private val context: Context = context private var mProgressDialog: ProgressDialog? = null override fun onPreExecute() { super.onPreExecute() // Create and show a progress dialog mProgressDialog = ProgressDialog(context) mProgressDialog?.setTitle("Downloading...") mProgressDialog?.setMessage("Please wait...") mProgressDialog?.setCancelable(false) mProgressDialog?.show() } override fun doInBackground(vararg params: String): String { val url = params[0] // Download the file val file = URL(url).openConnection().getInputStream() val bytes = file.readBytes() // S影音e the file to the device val path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() val fileName = "downloaded_file.jpg" val fileOutputStream = FileOutputStream("$path/$fileName") fileOutputStream.write(bytes) fileOutputStream.close() return "File downloaded successfully" } override fun onPostExecute(result: String) { super.onPostExecute(result) // Dismiss the progress dialog mProgressDialog?.dismiss() // Show a toast message Toast.makeText(context, result, Toast.LENGTH_SHORT).show() } } } ``` XML Layout ```xml xmlns:app="http://schemas.android/apk/res-auto" xmlns:tools="http://schemas.android/tools" android:layout_width="match_parent" android:layout_height="match_parent"> android:id="@+id/url_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter URL" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> android:id="@+id/download_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Download" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/url_edit_text" /> ```
Android/iOS/tvOS协同服务性能测试全解析
产品团队网络攻防演练Android/iOS/Windows/tvOS全集全流程