public class MainActivity extends AppCompatActivity implements View.OnClickListener {
DownloadManager downloadManager;
String _URL = "your URL";
long refer;
BroadcastReceiver downloadcomplete;
BroadcastReceiver notificationClick;
Button btnDownload;
public void startdownload() {
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(_URL);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDescription("My download").setTitle("Notification Title");
request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "your filename");
request.setVisibleInDownloadsUi(true);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
refer = downloadManager.enqueue(request);
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED);
notificationClick = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String extraID = DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS;
long[] references = intent.getLongArrayExtra(extraID);
for (long r : references) {
if (r == refer) {
// do something with download file}
}
}
};
registerReceiver(notificationClick, filter);
IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
downloadcomplete = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long r = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (refer == r) {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(r);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
//get status of the download
int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(columnIndex);
int filenameIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
String saveFilePath = cursor.getString(filenameIndex);
int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(columnReason);
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
Toast.makeText(getApplicationContext(), "STATUS_SUCCESSFUL", Toast.LENGTH_SHORT).show();
break;
case DownloadManager.STATUS_FAILED:
// do somethingbreak;
case DownloadManager.STATUS_PAUSED:
// do somethingbreak;
case DownloadManager.STATUS_PENDING:
// do somethingbreak;
case DownloadManager.STATUS_RUNNING:
// do somethingbreak;
}
}
}
};
registerReceiver(downloadcomplete, intentFilter);
}
@Override
package="map.conghuy.com.myapplication">
<!-- BEGIN_INCLUDE(manifest) --> <!-- Note that all required permissions are declared here in the Android manifest.
On Android M and above, use of these permissions is only requested at run time. -->
public class MainActivity extends SampleActivityBase
implements ActivityCompat.OnRequestPermissionsResultCallback {
public static final String TAG = "MainActivity";
private final int MY_PERMISSIONS_REQUEST_CODE = 1;
Button btn_deviceId;
TextView tv_deviceId;
TelephonyManager telephonyManager;
private boolean checkPermissions() {
if (ActivityCompat.checkSelfPermission(this,
public class ItemObject {
String name;
int photo;
public ItemObject(String name, int photo) {
this.name = name;
this.photo = photo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPhoto() {
return photo;
}
public void setPhoto(int photo) {
this.photo = photo;
}
}
RecyclerViewHolders class
public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView countryName;
public ImageView countryPhoto;
// add event click
public void onClick(View view, int position, boolean isLongClick) {
if (isLongClick)
Toast.makeText(mContext, "pos:" + position + " isLongClick", Toast.LENGTH_SHORT).show();
else