Code example for Context

Methods: getSystemServiceregisterReceiver

0
     * {@inheritDoc} 
     */ 
    @Override 
    public void setUp() throws Exception { 
        mContext = getInstrumentation().getContext();
        mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        mReceiver = registerNewMultipleDownloadsReceiver();
    } 
 
    /** 
     * Helper to verify the size of a file. 
     * 
     * @param pfd The input file to compare the size of 
     * @param size The expected size of the file 
     */ 
    protected void verifyFileSize(ParcelFileDescriptor pfd, long size) {
        assertEquals(pfd.getStatSize(), size);
    } 
 
    /** 
     * Helper to create and register a new MultipleDownloadCompletedReciever 
     * 
     * This is used to track many simultaneous downloads by keeping count of all the downloads 
     * that have completed. 
     * 
     * @return A new receiver that records and can be queried on how many downloads have completed. 
     */ 
    protected MultipleDownloadsCompletedReceiver registerNewMultipleDownloadsReceiver() { 
        MultipleDownloadsCompletedReceiver receiver = new MultipleDownloadsCompletedReceiver();
        mContext.registerReceiver(receiver, new IntentFilter(
                DownloadManager.ACTION_DOWNLOAD_COMPLETE));
        return receiver;
    } 
 
    /**