https://github.com/prana10/downloadersample
Sample Downloader Using WorkManager & HttpURLConnection in Java
https://github.com/prana10/downloadersample
android httpurlconnection java workmanager
Last synced: 4 months ago
JSON representation
Sample Downloader Using WorkManager & HttpURLConnection in Java
- Host: GitHub
- URL: https://github.com/prana10/downloadersample
- Owner: prana10
- Created: 2023-09-29T09:53:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-02T03:35:55.000Z (about 2 years ago)
- Last Synced: 2025-03-16T07:42:53.170Z (7 months ago)
- Topics: android, httpurlconnection, java, workmanager
- Language: Java
- Homepage:
- Size: 103 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Downloader Sample
Sample Downloader Using WorkManager & HttpURLConnection in Java# How To Use
To use this project. Please change the URL in the MainActivity.java file
```java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);// isi dengan url file zip yang ingin di download
// pastikan cek url nya secara benar agar file bisa di download
String url = "";// file lokasi output berada di : /data/user/0/com.garyle.downloadersample/files/file.zip
// ganti ekstensi file .zip nya dengan file yang ingin di download
String outputFilePath = getFilesDir().getAbsolutePath() + "/file.zip";Data inputData = new Data.Builder()
.putString("file_url", url)
.putString("output_file_path", outputFilePath)
.build();OneTimeWorkRequest downloadWorkRequest = new OneTimeWorkRequest.Builder(DownloadWorker.class)
.setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
.setInputData(inputData)
.build();triggerDownloadOnWiFi(downloadWorkRequest);
}
```
Adjust the file extension to the file you want to download.## To modify the notification, please visit the DownloadWorker.java file.
Please customize the Icon, Title, and Content text as you wish.
```java
private void showNotification(String message, int notificationId) {
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"downloader_notification_sample_channel",
NotificationManager.IMPORTANCE_DEFAULT
);notificationManager.createNotificationChannel(channel);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Download Status")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);notificationManager.notify(notificationId, builder.build());
}
```
## Acknowledgements
- [background Work with WorkManager in Java](https://developer.android.com/codelabs/android-workmanager-java#0)
- [HttpURLConnection Reference](https://developer.android.com/reference/java/net/HttpURLConnection)
- [WorkManager Reference](https://developer.android.com/reference/androidx/work/WorkManager)# Authors
- [@dhika_prana](https://www.instagram.com/dhika_prana/)