Lompat ke konten Lompat ke sidebar Lompat ke footer

Fungsi Programmatically Setelah Download File Dan Download Manager - Android Studio

Program Dan Fungsi Download manager Dan Juga Fungsi Setelah Download Dari Aplikasi Android

Programmatically Contoh Coding Dari Gsyntax Ultra Sound Untuk PUBG Mobile Versi Lama Terakhir V4.7.8.. 

public void soundquality() {

//Menampilkan Alert Dialog 

        new AlertDialog.Builder(Helper.this)
.setTitle("You Must Download Sound Ultra Paks!")
.setMessage("This Paks Official From PUBG Corp, it's very safe \n" +
"Note : \n" +
"- Size 42+MB\n" +
"- IF Download Failed Contact me IG @faranramdan(faster)\n" +
"OR via email : faranramdan@gmail.com(slowly)\n" +
"- Or Download manual : bit.ly/pubgsound2 \n")
.setPositiveButton("Download", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String url = "https://docs.google.com/uc?export=download&id=1--aPYynS2MbelaPoagAI1ZhK9Ky1fBD7";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle("Ultra Sound PUBGM 0.18.0");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}

// nama dan judul file yang di download

                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Officialpaks-PUBGM-FR.pak");
Toast.makeText(getApplicationContext(), "Downloading, Please Wait..", Toast.LENGTH_LONG).show();
//jika dowenload selesai
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create().show();
}
// Fungsi Setelah Tombol Di klik
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
// download complete will be eksekusi "public void compleatedownload()"
compleatedownload();
//automatic make usersettings

//Pengecekan Versi Yang Di Pilih
// 0 = Global
// 1 = KR
// 2 = VN
SharedPreferences sharedPref = getSharedPreferences("FileName", MODE_PRIVATE);
int spinnerValue = sharedPref.getInt("userChoiceSpinner", -1);
if (spinnerValue == 0) {
try {
// jika folder blum tersedia
if (!root.exists()) {
root.mkdirs();
}
//mulai eksekusi
File filepath = new File(root, soundq); // file path to save
FileWriter writer = new FileWriter(filepath);
writer.append("[SoundQuality]\n" +
"+CVars=SoundQualityType=2"); //write isi file
writer.flush();
writer.close();
Toast.makeText(getApplicationContext(), "Success Change Ultra Audio Quality", Toast.LENGTH_LONG).show();

} catch (IOException e) {
e.printStackTrace();
}
} else if (spinnerValue == 1) {
try {
// jika folder blum tersedia
if (!rootKR.exists()) {
rootKR.mkdirs();
}
//mulai eksekusi
File filepath = new File(rootKR, soundq); // file path to save
FileWriter writer = new FileWriter(filepath);
writer.append("[SoundQuality]\n" +
"+CVars=SoundQualityType=2"); //write isi file
writer.flush();
writer.close();
Toast.makeText(getApplicationContext(), "Success Change Ultra Audio Quality", Toast.LENGTH_LONG).show();

} catch (IOException e) {
e.printStackTrace();
}
} else if (spinnerValue == 2) {
try {
// jika folder blum tersedia
if (!rootVN.exists()) {
rootVN.mkdirs();
}
//mulai eksekusi
File filepath = new File(rootVN, soundq); // file path to save
FileWriter writer = new FileWriter(filepath);
writer.append("[SoundQuality]\n" +
"+CVars=SoundQualityType=2"); //write isi file
writer.flush();
writer.close();
Toast.makeText(getApplicationContext(), "Success Change Ultra Audio Quality", Toast.LENGTH_LONG).show();

} catch (IOException e) {
e.printStackTrace();
}
}

}
};

//fungsi setelelah download selesai 


public void compleatedownload() {
Toast.makeText(getApplicationContext(), "Download Finish", Toast.LENGTH_LONG).show();
// the file to be moved or copied
File sourceLocation = new File(paksdownload + "/Officialpaks-PUBGM-FR.pak");
// make sure your target location folder exists!
File directorysound = new File(Environment.getExternalStorageDirectory(), "/android/data/com.tencent.ig/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/Paks");
File targetLocation = new File(directorysound + "/res_audiohigh_0.19.0.13900.pak");

File directorysoundKR = new File(Environment.getExternalStorageDirectory(), "/android/data/com.pubg.krmobile/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/Paks");
File targetLocationKR = new File(directorysoundKR + "/res_audiohigh_0.19.0.13900.pak");

File directorysoundvn = new File(Environment.getExternalStorageDirectory(), "/android/data/com.vng.pubgmobile/files/UE4Game/ShadowTrackerExtra/ShadowTrackerExtra/Saved/Paks");
File targetLocationVN = new File(directorysoundvn + "/res_audiohigh_0.19.0.13900.pak");

// just to take note of the location sources
Log.v(TAG, "sourceLocation: " + sourceLocation);
Log.v(TAG, "targetLocation: " + targetLocation);
try {
// 1 = move the file, 2 = copy the file
int actionChoice = 2;
// moving the file to another directory
if (actionChoice == 1) {
if (sourceLocation.renameTo(targetLocation)) {
Log.v(TAG, "Move file successful.");
Toast.makeText(getApplicationContext(), "UserCustom.ini Detected", Toast.LENGTH_LONG).show();
} else {
Log.v(TAG, "Move file failed.");
Toast.makeText(getApplicationContext(), "Nothing UserCustom.ini!", Toast.LENGTH_LONG).show();
}
}
// we will copy the file
else {
// make sure the target file exists
if (sourceLocation.exists()) {

//Pengecekan Versi Yang Di Pilih
// 0 = Global
// 1 = KR
// 2 = VN
SharedPreferences sharedPref = getSharedPreferences("FileName", MODE_PRIVATE);
int spinnerValue = sharedPref.getInt("userChoiceSpinner", -1);
if (spinnerValue == 0) {
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v(TAG, "Copy file successful.");
} else if (spinnerValue == 1) {
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocationKR);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v(TAG, "Copy file successful.");
} else if (spinnerValue == 2) {
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocationVN);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v(TAG, "Copy file successful.");
}

} else {
Log.v(TAG, "Copy file failed. Source file missing.");
}
}
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

close