Example usage for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE

List of usage examples for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE

Introduction

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

Prototype

String ACTION_DOWNLOAD_COMPLETE

To view the source code for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE.

Click Source Link

Document

Broadcast intent action sent by the download manager when a download completes.

Usage

From source file:dentex.youtube.downloader.service.AutoUpgradeApkService.java

@Override
public void onCreate() {
    Utils.logger("d", "service created", DEBUG_TAG);
    BugSenseHandler.initAndStartSession(this, YTD.BugsenseApiKey);
    BugSenseHandler.leaveBreadcrumb("AutoUpgradeApkService_onCreate");
    registerReceiver(apkReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

    currentVersion = UpdateHelper.findCurrentAppVersion(this);
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected() && matchedVersion != "n.a.") {
        try {//from  ww  w  .  j a v a  2 s  .c  om
            //init version and changelog
            matchedChangeLog = null;
            matchedVersion = null;

            asyncAutoUpdate = new AsyncUpdate();
            asyncAutoUpdate.execute(getString(R.string.apk_upgrade_sourceforge_link));
        } catch (NullPointerException e) {
            Log.e(DEBUG_TAG, "unable to retrieve update data.");
        }
    } else {
        Log.e(DEBUG_TAG, getString(R.string.no_net));
    }
}

From source file:es.usc.citius.servando.calendula.fragments.MedicinesListFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    getActivity().registerReceiver(onNotificationClick,
            new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED));
}

From source file:pe.kr.crasy.parse_launch.MainActivity.java

License:asdf

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBuilder = new NotificationCompat.Builder(this);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder.setSmallIcon(R.mipmap.ic_download_grey600_36dp);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w ww  . j  av  a2 s  .c om
    actionBar = getSupportActionBar();

    calendar = Calendar.getInstance(Locale.KOREA);

    setTitle("" + calendar.get(Calendar.YEAR) + " " + (calendar.get(Calendar.MONTH) + 1) + " "
            + calendar.get(Calendar.DAY_OF_MONTH) + "? ?");

    FloatingActionButton fabDownload = (FloatingActionButton) findViewById(R.id.Button_Download_All);
    FloatingActionButton fabRemoveData = (FloatingActionButton) findViewById(R.id.Button_Remove_All_Data);
    FloatingActionButton fabShowInCalender = (FloatingActionButton) findViewById(R.id.Button_Show_In_Calender);
    FloatingActionButton fabShowLicense = (FloatingActionButton) findViewById(R.id.Button_Show_Setting);
    famMultipleActionsDown = (FloatingActionsMenu) findViewById(R.id.multiple_actions_down);
    fabDownload.setOnClickListener(new fabOnclickListener());
    fabRemoveData.setOnClickListener(new fabOnclickListener());
    fabShowInCalender.setOnClickListener(new fabOnclickListener());
    fabShowLicense.setOnClickListener(new fabOnclickListener());

    intentFilter = new IntentFilter(); //?   
    intentFilter.addAction(getPackageName() + "Show_Launch_List"); //?  ? ?    
    intentFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); //HWP ??  ??    
    broadcastReceiver = new Show_Launch_List(); //Inner class Show_Launch_List()  
    registerReceiver(broadcastReceiver, intentFilter); //  ?

    ListView Launch_List = (ListView) findViewById(R.id.Launch_List);
    Launch_List_Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    Launch_List.setAdapter(Launch_List_Adapter);

    RealmResults<LaunchStore> realmResults;
    RealmResults<LaunchList> realmResultsList;
    realm = Realm.getInstance(this);
    realmResults = realm.where(LaunchStore.class).findAll(); // ? ? ?  ?
    Iterator<LaunchStore> iterator = realmResults.iterator();
    Boolean test = false;
    LaunchStore launchstore;
    while (iterator.hasNext()) {
        launchstore = iterator.next();
        if (simpleDateFormat.format(launchstore.getDate()).equals(simpleDateFormat.format(new Date()))) {
            realmResultsList = launchstore.getLaunchList().where().findAll();
            Iterator<LaunchList> launchListIterator = realmResultsList.listIterator();
            while (launchListIterator.hasNext()) {
                Today_Launch.add(launchListIterator.next().getLaunch());
            }
            sendBroadcast(new Intent(getPackageName() + "Show_Launch_List"));
            test = true;
            break;
        }
    }
    if (!test) {
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
        if ((sharedPreferences.getBoolean("UpdateLaunchOnlyWIFI", true) && isWifi().equals("WIFI"))
                || !sharedPreferences.getBoolean("UpdateLaunchOnlyWIFI", true)) {
            new Thread(new Runnable() { //? ?  
                private Realm realm_2;

                @Override
                public void run() {
                    Log.d("dd", "loaded download");
                    try {
                        realm_2 = Realm.getInstance(getApplicationContext());
                        Document doc = Jsoup.connect(
                                "http://www.sugong.org/main.php?menugrp=060602&master=meal2&act=list&SearchYear=2015&SearchMonth="
                                        + (calendar.get(Calendar.MONTH) + 1) + "&SearchDay="
                                        + calendar.get(Calendar.DAY_OF_MONTH) + "#diary_list")
                                .get();
                        Elements elements = doc.select(".meal_table");
                        String[] strSplit = elements.text().split("? ? ");
                        realm_2.beginTransaction();
                        LaunchStore launchStore = realm_2.createObject(LaunchStore.class);
                        launchStore.setDate(new Date());
                        LaunchList launchList;
                        if (strSplit.length >= 2) { //?  ? 1?
                            strSplit = strSplit[1].split(",");
                            for (String s : strSplit) {
                                Log.d("dd", s.trim());
                                Today_Launch.add(s.trim());
                                launchList = realm_2.createObject(LaunchList.class);
                                launchList.setLaunch(s.trim());
                                launchStore.getLaunchList().add(launchList);
                            }
                        } else {
                            launchList = realm_2.createObject(LaunchList.class);
                            launchList.setLaunch("No Launch Today");
                            launchStore.getLaunchList().add(launchList);
                            Today_Launch.add("No Launch Today");
                        }
                        realm_2.commitTransaction();
                    } catch (IOException e) {
                        Today_Launch.add(" !!!");
                        e.printStackTrace();
                    }

                    sendBroadcast(new Intent(getPackageName() + "Show_Launch_List")); // ?? 
                }
            }).start();
        } else {
            Launch_List_Adapter.clear();
            Launch_List_Adapter.add(
                    "? WI-FI       .");
        }
    }
}

From source file:dentex.youtube.downloader.service.DownloadsService.java

@Override
public void onCreate() {
    Utils.logger("d", "service created", DEBUG_TAG);
    BugSenseHandler.initAndStartSession(this, YTD.BugsenseApiKey);
    settings = getSharedPreferences(PREFS_NAME, 0);
    nContext = getBaseContext();/*from w  w w  . ja  va 2s .  com*/
    registerReceiver(downloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:com.rdrive.updateapk.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn_update = (Button) findViewById(R.id.button_update);
    btn_update.setEnabled(false);//  w  w  w . j a  v a 2 s .  c om

    currentVersionValue = (TextView) findViewById(R.id.currentVersionValue);
    lastVersionValue = (TextView) findViewById(R.id.lastVersionValue);

    dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

    new CheckUpdate() {
        @Override
        protected void onPostExecute(Boolean aBoolean) {
            currentVersionValue.setText(this.getCurrentVersion().toString());
            lastVersionValue.setText(this.getLastVersion().toString());
            if (!aBoolean) {
                btn_update.setEnabled(true);
            }
        }
    }.execute(getContext());

    btn_update.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT > 22) {
                if (ContextCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(),
                            new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            ASK_WRITE_EXTERNAL_STORAGE_FOR_UPDATE);
                    return;
                }
            }
            downloadLastVersion(getContext(), dm);
        }
    });

    BroadcastReceiver attachmentDownloadCompleteReceive = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                Cursor cursor = dm.query(query);
                if (cursor.moveToFirst()) {
                    int downloadStatus = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
                    String downloadLocalUri = cursor
                            .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    if ((downloadStatus == DownloadManager.STATUS_SUCCESSFUL) && downloadLocalUri != null) {
                        openApk(getContext(), downloadLocalUri);
                    }
                }
                cursor.close();
            }
        }
    };

    registerReceiver(attachmentDownloadCompleteReceive,
            new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:com.tfc.webviewer.ui.WebViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //noinspection ConstantConditions
    getSupportActionBar().hide();/*w ww  .  ja va2 s . co m*/

    IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    filter.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED);
    registerReceiver(mDownloadReceiver, filter);

    mUrl = getIntent().getStringExtra(EXTRA_URL);

    setContentView(R.layout.a_web_viewer);
    bindView();

    mPresenter = new WebViewPresenterImpl(this, this);
    mPresenter.validateUrl(mUrl);
}

From source file:org.openbmap.activities.DialogPreferenceCatalogs.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *//*  www . j  ava2 s .  co  m*/
@SuppressLint("NewApi")
private void initDownloadManager() {
    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:org.openbmap.activities.DialogPreferenceMaps.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *///from w w  w .j a  v a 2 s  .c o m
@SuppressLint("NewApi")
private void initDownloadManager() {

    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:de.elanev.studip.android.app.frontend.courses.CourseDocumentsFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // registering the broadcast receiver for completed downloads
    activity.registerReceiver(mDownloadManagerReceiver,
            new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER);
    setContentView(R.layout.activity_externallink_webview);
    Bundle bundle = getIntent().getExtras();
    fileUrl = bundle.getString("url", "https://www.digipost.no");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  w  ww . j a  va 2 s .  co  m
    actionBar = getSupportActionBar();
    if (actionBar != null) {
        setActionBarTitle(fileUrl);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setBackgroundDrawable(new ColorDrawable(0xff2E2E2E));

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(
                    ContextCompat.getColor(this, R.color.metadata_externalbrowser_top_background));
        }
    }

    progressSpinner = (ProgressBar) findViewById(R.id.externallink_spinner);
    webView = (WebView) findViewById(R.id.externallink_webview);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDomStorageEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(true);
    enableCookies(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (firstLoad) {
                progressSpinner.setVisibility(View.GONE);
                webView.setVisibility(View.VISIBLE);
                firstLoad = false;
            }
            setActionBarTitle(view.getUrl());
        }
    });

    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, final String userAgent, final String content,
                final String mimeType, final long contentLength) {
            fileName = URLUtil.guessFileName(url, content, mimeType);
            fileUrl = url;
            onComplete = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                        showDownloadSuccessDialog(context);
                    }
                }
            };

            registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
            if (!mimeType.equals("text/html")) {
                if (FileUtilities.isStorageWriteAllowed(getApplicationContext())) {
                    showDownloadDialog(userAgent, content, mimeType, contentLength);
                } else {
                    showMissingPermissionsDialog();
                }
            }
        }
    });

    if (FileUtilities.isStorageWriteAllowed(this)) {
        webView.loadUrl(fileUrl);
    } else {
        showPermissionsDialog();
    }
}