Example usage for android.app DownloadManager getClass

List of usage examples for android.app DownloadManager getClass

Introduction

In this page you can find the example usage for android.app DownloadManager getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.chromium.chrome.browser.download.DownloadManagerDelegate.java

/**
 * @see android.app.DownloadManager#addCompletedDownload(String, String, boolean, String,
 * String, long, boolean)//from www .  ja va  2 s.  c  o  m
 */
protected long addCompletedDownload(String fileName, String description, String mimeType, String path,
        long length, String originalUrl, String referer, String downloadGuid) {
    DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext);
    boolean useSystemNotification = !notificationManager.areNotificationsEnabled();
    long downloadId = -1;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        Class<?> c = manager.getClass();
        try {
            Class[] args = { String.class, String.class, boolean.class, String.class, String.class, long.class,
                    boolean.class, Uri.class, Uri.class };
            Method method = c.getMethod("addCompletedDownload", args);
            Uri originalUri = Uri.parse(originalUrl);
            Uri refererUri = referer == null ? Uri.EMPTY : Uri.parse(referer);
            downloadId = (Long) method.invoke(manager, fileName, description, true, mimeType, path, length,
                    useSystemNotification, originalUri, refererUri);
        } catch (SecurityException e) {
            Log.e(TAG, "Cannot access the needed method.");
        } catch (NoSuchMethodException e) {
            Log.e(TAG, "Cannot find the needed method.");
        } catch (InvocationTargetException e) {
            Log.e(TAG, "Error calling the needed method.");
        } catch (IllegalAccessException e) {
            Log.e(TAG, "Error accessing the needed method.");
        }
    } else {
        downloadId = manager.addCompletedDownload(fileName, description, true, mimeType, path, length,
                useSystemNotification);
    }
    addDownloadIdMapping(downloadId, downloadGuid);
    return downloadId;
}