id="@+id/download_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp"> android:id="@+id/download_button_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/download" /> android:id="@+id/download_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> ``` ```kotlin private fun downloadApk() { val button = findViewById(R.id.download_button_text) val progressBar = findViewById(R.id.download_progress) button.isEnabled = false progressBar.visibility = View.VISIBLE // Replace "YOUR_APK_URL" with the actual URL of the APK file to download val url = "YOUR_APK_URL" val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) val fileName = "hua_run.apk" val request = DownloadManager.Request(Uri.parse(url)) request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager val downloadId = downloadManager.enqueue(request) val broadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) if (id == downloadId) { unregisterReceiver(this) Toast.makeText(this@MainActivity, "Download complete", Toast.LENGTH_SHORT).show() button.isEnabled = true progressBar.visibility = View.GONE } } } registerReceiver(broadcastReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) } ``` iOS ```swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50)) button.setTitle("Download", for: .normal) button.addTarget(self, action: selector(downloadApk), for: .touchUpInside) view.addSubview(button) } @objc func downloadApk() { guard let url = URL(string: "YOUR_APK_URL") else { return } let task = URLSession.shared.downloadTask(with: url) { (location, response, error) in if let error = error { print("Error downloading file: \(error.localizedDescription)") return } guard let location = location else { return } do { let data = try Data(contentsOf: location) // S影音e the data to the user's device let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let filePath = documentsPath.appendingPathComponent("hua_run.apk") try data.write(to: filePath, options: .atomic) // Open the file in the default app for viewing let fileURL = URL(fileURLWithPath: filePath.path) let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil) present(activityViewController, animated: true) } catch { print("Error s视频ing file: \(error.localizedDescription)") } } task.resume() } } ```