| | |
| | | import android.net.ConnectivityManager; |
| | | import android.net.NetworkInfo; |
| | | import android.net.Uri; |
| | | import android.os.Build; |
| | | import android.util.Log; |
| | | |
| | | /** |
| | |
| | | String action = intent.getAction(); |
| | | /*if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { |
| | | startService(context); |
| | | } else */if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { |
| | | } else */ |
| | | if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { |
| | | NetworkInfo info = (NetworkInfo) |
| | | intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); |
| | | if (info != null && info.isConnected()) { |
| | |
| | | |
| | | /** |
| | | * Hide a system notification for a download. |
| | | * @param uri URI to update the download |
| | | * |
| | | * @param uri URI to update the download |
| | | * @param cursor Cursor for reading the download's fields |
| | | */ |
| | | private void hideNotification(Context context, Uri uri, Cursor cursor) { |
| | |
| | | private void openDownload(Context context, Cursor cursor) { |
| | | String filename = cursor.getString(cursor.getColumnIndexOrThrow(Downloads._DATA)); |
| | | String mimetype = |
| | | cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE)); |
| | | cursor.getString(cursor.getColumnIndexOrThrow(Downloads.COLUMN_MIME_TYPE)); |
| | | Uri path = Uri.parse(filename); |
| | | // If there is no scheme, then it must be a file |
| | | if (path.getScheme() == null) { |
| | |
| | | |
| | | /** |
| | | * Notify the owner of a running download that its notification was clicked. |
| | | * |
| | | * @param intent the broadcast intent sent by the notification manager |
| | | * @param cursor Cursor for reading the download's fields |
| | | */ |
| | |
| | | } |
| | | |
| | | private void startService(Context context) { |
| | | context.startService(new Intent(context, DownloadService.class)); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| | | context.startForegroundService(new Intent(context, DownloadService.class)); |
| | | } else { |
| | | context.startService(new Intent(context, DownloadService.class)); |
| | | } |
| | | |
| | | } |
| | | } |