-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from banditAmit/amit
Amit
- Loading branch information
Showing
8 changed files
with
317 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/BugBazaar/utils/FileDownloadWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.BugBazaar.utils; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.work.Worker; | ||
import androidx.work.WorkerParameters; | ||
import androidx.work.Data; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class FileDownloadWorker extends Worker { | ||
public FileDownloadWorker(@NonNull Context context, @NonNull WorkerParameters params) { | ||
super(context, params); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Result doWork() { | ||
String fileUrl = getInputData().getString("FILE_URL"); | ||
try { | ||
URL url = new URL(fileUrl); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.connect(); | ||
|
||
File outputFile = new File(getApplicationContext().getFilesDir(), "abcd.apk"); // Modify the file name and extension as needed | ||
FileOutputStream outputStream = new FileOutputStream(outputFile); | ||
InputStream inputStream = connection.getInputStream(); | ||
|
||
byte[] data = new byte[1024]; | ||
int count; | ||
while ((count = inputStream.read(data)) != -1) { | ||
outputStream.write(data, 0, count); | ||
} | ||
|
||
outputStream.flush(); | ||
outputStream.close(); | ||
inputStream.close(); | ||
|
||
return Result.success(); | ||
} catch (Exception e) { | ||
Log.d("hello", String.valueOf(e)); | ||
|
||
e.printStackTrace(); | ||
return Result.failure(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.BugBazaar.utils; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
|
||
public class NetworkUtils { | ||
public static boolean isNetworkAvailable(Context context) { | ||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
if (connectivityManager != null) { | ||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); | ||
return activeNetworkInfo != null && activeNetworkInfo.isConnected(); | ||
} | ||
return false; | ||
} | ||
|
||
public static void showNoInternetDialog(Context context) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
builder.setTitle("No Internet Access"); | ||
builder.setMessage("Open App with Network Access & get voucher on First Run!"); | ||
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
dialog.dismiss(); | ||
} | ||
}); | ||
AlertDialog dialog = builder.create(); | ||
dialog.show(); | ||
} | ||
|
||
public static void showExeptionDialog(Context context) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(context); | ||
builder.setTitle("!!"); | ||
builder.setMessage("Something Happened bad!"); | ||
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
dialog.dismiss(); | ||
} | ||
}); | ||
AlertDialog dialog = builder.create(); | ||
dialog.show(); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.