本文整理汇总了Java中org.fdroid.fdroid.net.DownloaderService类的典型用法代码示例。如果您正苦于以下问题:Java DownloaderService类的具体用法?Java DownloaderService怎么用?Java DownloaderService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DownloaderService类属于org.fdroid.fdroid.net包,在下文中一共展示了DownloaderService类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ViewHolder
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
ViewHolder() {
// TODO: Unregister receivers correctly...
Apk apk = getApkToInstall();
String url = Utils.getApkUrl(apk.repoAddress, apk);
localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(downloadProgressReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(interruptedReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_INTERRUPTED));
}
示例2: autoDownloadUpdates
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
private void autoDownloadUpdates(String repoAddress) {
Cursor cursor = getContentResolver().query(
AppProvider.getCanUpdateUri(),
new String[]{
AppProvider.DataColumns.PACKAGE_NAME,
AppProvider.DataColumns.SUGGESTED_VERSION_CODE,
}, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
App app = new App(cursor);
Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode, new String[]{
ApkProvider.DataColumns.NAME,
});
String urlString = Utils.getApkUrl(repoAddress, apk);
DownloaderService.queue(this, app.packageName, urlString);
cursor.moveToNext();
}
cursor.close();
}
}
示例3: reset
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
private boolean reset(String packageName) {
Utils.debugLog(TAG, "Getting application details for " + packageName);
App newApp = null;
String urlString = getPreferences(MODE_PRIVATE).getString(packageName, null);
if (DownloaderService.isQueuedOrActive(urlString)) {
activeDownloadUrlString = urlString;
} else {
// this URL is no longer active, remove it
PreferencesCompat.apply(getPreferences(MODE_PRIVATE).edit().remove(packageName));
}
if (!TextUtils.isEmpty(packageName)) {
newApp = AppProvider.Helper.findByPackageName(getContentResolver(), packageName);
}
setApp(newApp);
return this.app != null;
}
示例4: setApp
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
public void setApp(@NonNull App app) {
if (this.app == null || !this.app.packageName.equals(app.packageName)) {
this.app = app;
List<Apk> availableApks = ApkProvider.Helper.findAppVersionsByRepo(getActivity(), app, repo);
if (availableApks.size() > 0) {
// Swap repos only add one version of an app, so we will just ask for the first apk.
this.apk = availableApks.get(0);
}
if (apk != null) {
String urlString = apk.getUrl();
// TODO unregister receivers? or will they just die with this instance
IntentFilter downloadFilter = DownloaderService.getIntentFilter(urlString);
localBroadcastManager.registerReceiver(downloadReceiver, downloadFilter);
}
// NOTE: Instead of continually unregistering and re-registering the observer
// (with a different URI), this could equally be done by only having one
// registration in the constructor, and using the ContentObserver.onChange(boolean, URI)
// method and inspecting the URI to see if it matches. However, this was only
// implemented on API-16, so leaving like this for now.
getActivity().getContentResolver().unregisterContentObserver(appObserver);
getActivity().getContentResolver().registerContentObserver(
AppProvider.getSpecificAppUri(this.app.packageName, this.app.repoId), true, appObserver);
}
resetView();
}
示例5: install
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
public void install(@NonNull final App app) {
final Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode);
String urlString = Utils.getApkUrl(apk.repoAddress, apk);
downloadCompleteReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String path = intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH);
handleDownloadComplete(new File(path), app.packageName, intent.getDataString());
}
};
localBroadcastManager.registerReceiver(downloadCompleteReceiver,
DownloaderService.getIntentFilter(urlString, Downloader.ACTION_COMPLETE));
DownloaderService.queue(this, app.packageName, urlString);
}
示例6: onResumeFragments
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
@Override
protected void onResumeFragments() {
super.onResumeFragments();
headerFragment = (AppDetailsHeaderFragment) getSupportFragmentManager().findFragmentById(R.id.header);
refreshApkList();
supportInvalidateOptionsMenu();
if (DownloaderService.isQueuedOrActive(activeDownloadUrlString)) {
registerDownloaderReceivers();
}
}
示例7: registerDownloaderReceivers
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
private void registerDownloaderReceivers() {
if (activeDownloadUrlString != null) { // if a download is active
String url = activeDownloadUrlString;
localBroadcastManager.registerReceiver(startedReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(progressReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(completeReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(interruptedReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_INTERRUPTED));
}
}
示例8: onClick
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
/**
* Cancels download and hides progress bar.
*/
@Override
public void onClick(View view) {
AppDetails appDetails = (AppDetails) getActivity();
if (appDetails == null || appDetails.activeDownloadUrlString == null) {
return;
}
DownloaderService.cancel(getContext(), appDetails.activeDownloadUrlString);
}
示例9: stopServices
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
/**
* Stops all running services, so nothing can pop up and reveal F-Droid's existence on the system
*/
private static void stopServices(Context context) {
context.stopService(new Intent(context, UpdateService.class));
context.stopService(new Intent(context, DownloaderService.class));
context.stopService(new Intent(context, InstallerService.class));
context.stopService(new Intent(context, CleanCacheService.class));
context.stopService(new Intent(context, WifiStateChangeService.class));
context.stopService(new Intent(context, SwapService.class));
context.stopService(new Intent(context, InstallManagerService.class));
context.stopService(new Intent(context, InstallHistoryService.class));
context.stopService(new Intent(context, CacheSwapAppsService.class));
context.stopService(new Intent(context, InstalledAppProviderService.class));
context.stopService(new Intent(context, AppUpdateStatusService.class));
}
示例10: getObb
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
/**
* Check if any OBB files are available, and if so, download and install them. This
* also deletes any obsolete OBB files, per the spec, since there can be only one
* "main" and one "patch" OBB installed at a time.
*
* @see <a href="https://developer.android.com/google/play/expansion-files.html">APK Expansion Files</a>
*/
private void getObb(final String urlString, String obbUrlString,
final File obbDestFile, final String sha256) {
if (obbDestFile == null || obbDestFile.exists() || TextUtils.isEmpty(obbUrlString)) {
return;
}
final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Downloader.ACTION_STARTED.equals(action)) {
Utils.debugLog(TAG, action + " " + intent);
} else if (Downloader.ACTION_PROGRESS.equals(action)) {
int bytesRead = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, 0);
int totalBytes = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, 0);
appUpdateStatusManager.updateApkProgress(urlString, totalBytes, bytesRead);
} else if (Downloader.ACTION_COMPLETE.equals(action)) {
localBroadcastManager.unregisterReceiver(this);
File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
Uri localApkUri = Uri.fromFile(localFile);
Utils.debugLog(TAG, "OBB download completed " + intent.getDataString()
+ " to " + localApkUri);
try {
if (Hasher.isFileMatchingHash(localFile, sha256, "SHA-256")) {
Utils.debugLog(TAG, "Installing OBB " + localFile + " to " + obbDestFile);
FileUtils.forceMkdirParent(obbDestFile);
FileUtils.copyFile(localFile, obbDestFile);
FileFilter filter = new WildcardFileFilter(
obbDestFile.getName().substring(0, 4) + "*.obb");
for (File f : obbDestFile.getParentFile().listFiles(filter)) {
if (!f.equals(obbDestFile)) {
Utils.debugLog(TAG, "Deleting obsolete OBB " + f);
FileUtils.deleteQuietly(f);
}
}
} else {
Utils.debugLog(TAG, localFile + " deleted, did not match hash: " + sha256);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
FileUtils.deleteQuietly(localFile);
}
} else if (Downloader.ACTION_INTERRUPTED.equals(action)) {
localBroadcastManager.unregisterReceiver(this);
} else if (Downloader.ACTION_CONNECTION_FAILED.equals(action)) {
DownloaderService.queue(context, urlString, 0, urlString);
} else {
throw new RuntimeException("intent action not handled!");
}
}
};
DownloaderService.queue(this, obbUrlString, 0, obbUrlString);
localBroadcastManager.registerReceiver(downloadReceiver,
DownloaderService.getIntentFilter(obbUrlString));
}
示例11: startDownload
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
private void startDownload(Apk apk, String repoAddress) {
activeDownloadUrlString = Utils.getApkUrl(repoAddress, apk);
registerDownloaderReceivers();
headerFragment.startProgress();
DownloaderService.queue(this, apk.packageName, activeDownloadUrlString);
}
示例12: getObb
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
/**
* Check if any OBB files are available, and if so, download and install them. This
* also deletes any obsolete OBB files, per the spec, since there can be only one
* "main" and one "patch" OBB installed at a time.
*
* @see <a href="https://developer.android.com/google/play/expansion-files.html">APK Expansion Files</a>
*/
private void getObb(final String urlString, String obbUrlString,
final File obbDestFile, final String sha256) {
if (obbDestFile == null || obbDestFile.exists() || TextUtils.isEmpty(obbUrlString)) {
return;
}
final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!running) {
localBroadcastManager.unregisterReceiver(this);
return;
}
String action = intent.getAction();
if (Downloader.ACTION_STARTED.equals(action)) {
Utils.debugLog(TAG, action + " " + intent);
} else if (Downloader.ACTION_PROGRESS.equals(action)) {
int bytesRead = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, 0);
int totalBytes = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, 0);
appUpdateStatusManager.updateApkProgress(urlString, totalBytes, bytesRead);
} else if (Downloader.ACTION_COMPLETE.equals(action)) {
localBroadcastManager.unregisterReceiver(this);
File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
Uri localApkUri = Uri.fromFile(localFile);
Utils.debugLog(TAG, "OBB download completed " + intent.getDataString()
+ " to " + localApkUri);
try {
if (Hasher.isFileMatchingHash(localFile, sha256, "SHA-256")) {
Utils.debugLog(TAG, "Installing OBB " + localFile + " to " + obbDestFile);
FileUtils.forceMkdirParent(obbDestFile);
FileUtils.copyFile(localFile, obbDestFile);
FileFilter filter = new WildcardFileFilter(
obbDestFile.getName().substring(0, 4) + "*.obb");
for (File f : obbDestFile.getParentFile().listFiles(filter)) {
if (!f.equals(obbDestFile)) {
Utils.debugLog(TAG, "Deleting obsolete OBB " + f);
FileUtils.deleteQuietly(f);
}
}
} else {
Utils.debugLog(TAG, localFile + " deleted, did not match hash: " + sha256);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
FileUtils.deleteQuietly(localFile);
}
} else if (Downloader.ACTION_INTERRUPTED.equals(action)) {
localBroadcastManager.unregisterReceiver(this);
} else if (Downloader.ACTION_CONNECTION_FAILED.equals(action)) {
DownloaderService.queue(context, urlString, 0, urlString);
} else {
throw new RuntimeException("intent action not handled!");
}
}
};
DownloaderService.queue(this, obbUrlString, 0, obbUrlString);
localBroadcastManager.registerReceiver(downloadReceiver,
DownloaderService.getIntentFilter(obbUrlString));
}
示例13: restoreProgressBarOnResume
import org.fdroid.fdroid.net.DownloaderService; //导入依赖的package包/类
/**
* After resuming the fragment, decide whether or not we need to show the progress bar.
* Also, put an appropriate message depending on whether or not the download is active or
* just queued.
*
* NOTE: this can't be done in the `updateViews` method as it currently stands. The reason
* is because that method gets called all the time, for all sorts of reasons. The progress
* bar is updated with actual progress values in response to async broadcasts. If we always
* tried to force the progress bar in `updateViews`, it would override the values that were
* set by the async progress broadcasts.
*/
private void restoreProgressBarOnResume() {
if (appDetails.activeDownloadUrlString != null) {
// We don't actually know what the current progress is, so this will show an indeterminate
// progress bar until the first progress/complete event we receive.
final String message = DownloaderService.isQueued(appDetails.activeDownloadUrlString)
? getString(R.string.download_pending)
: "";
showIndeterminateProgress(message);
}
}