public class MainActivity extends AppCompatActivity {
Button download;
TextView downloadCount;
ProgressBar progressBar;
Future downloading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Enable global Ion logging
Ion.getDefault(this).configure().setLogging("ion-sample", Log.DEBUG);
setContentView(R.layout.activity_main);
download = (Button) findViewById(R.id.download);
downloadCount = (TextView) findViewById(R.id.download_count);
progressBar = (ProgressBar) findViewById(R.id.progress);
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/dir1/dir2");
if (!dir.exists()) {
dir.mkdirs();
}
final File file = new File(dir, "filename.zip");
download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (downloading != null && !downloading.isCancelled()) {
resetDownload();
return;
}
download.setText("Cancel");
// this is a 180MB zip file to test with
downloading = Ion.with(MainActivity.this)
.load("http://cdn.p30download.com/?b=p30dl-software&f=PCWinSoft.1AVMonitor.v1.9.1.50_p30download.com.rar")
// attach the percentage report to a progress bar.
// can also attach to a ProgressDialog with progressDialog.
.progressBar(progressBar)
// callbacks on progress can happen on the UI thread
// via progressHandler. This is useful if you need to update a TextView.
// Updates to TextViews MUST happen on the UI thread.
.progressHandler(new ProgressCallback() {
@Override
public void onProgress(long downloaded, long total) {
downloadCount.setText("" + downloaded + " / " + total);
}
})
// write to a file
.write(file)
// run a callback on completion
.setCallback(new FutureCallback() {
@Override
public void onCompleted(Exception e, File result) {
resetDownload();
if (e != null) {
Toast.makeText(MainActivity.this, "Error downloading file", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(MainActivity.this, "File upload complete", Toast.LENGTH_LONG).show();
}
});
}
});
}
void resetDownload() {
// cancel any pending download
downloading.cancel();
downloading = null;
// reset the ui
download.setText("Download");
downloadCount.setText(null);
progressBar.setProgress(0);
}
}
Я пишу приведенные выше коды, но не знаю, как мне записать этот код в сервис и загрузить файл в фоновом режиме.
File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/dir1/dir2"); if (!dir.exists()) { dir.mkdirs(); } final File file = new File(dir, "filename.zip");
download.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (downloading != null && !downloading.isCancelled()) { resetDownload(); return; }
download.setText("Cancel"); // this is a 180MB zip file to test with downloading = Ion.with(MainActivity.this) .load("http://cdn.p30download.com/?b=p30dl-software&f=PCWinSoft.1AVMonitor.v1.9.1.50_p30download.com.rar") // attach the percentage report to a progress bar. // can also attach to a ProgressDialog with progressDialog. .progressBar(progressBar) // callbacks on progress can happen on the UI thread // via progressHandler. This is useful if you need to update a TextView. // Updates to TextViews MUST happen on the UI thread. .progressHandler(new ProgressCallback() { @Override public void onProgress(long downloaded, long total) { downloadCount.setText("" + downloaded + " / " + total); } }) // write to a file .write(file) // run a callback on completion .setCallback(new FutureCallback() { @Override public void onCompleted(Exception e, File result) { resetDownload(); if (e != null) { Toast.makeText(MainActivity.this, "Error downloading file", Toast.LENGTH_LONG).show(); return; } Toast.makeText(MainActivity.this, "File upload complete", Toast.LENGTH_LONG).show(); } }); } }); }
Я пытаюсь установить pyautogui с помощью cmd (Python 3.12 (64-бит)). Тем не менее, я получаю следующее сообщение об ошибке.
>>> pip install pyautogui
File , line 1
pip install pyautogui
^^^^^^^
Можете ли вы помочь мне определить проблему и дать...
В моем приложении я должен использовать ViewPager2 в Service .
Я хочу обрабатывать UI в сервисе , но я хочу знать, использую ли я ViewPager внутри сервиса , может ли он снизиться производительность приложения?
У меня есть несколько сервисов, и в...