The error appears in RecyclerView Adapter on different versions of android and devices. Im retrieving information about download progress every second and show percents on item layout.
@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
final Download item = downloads.get(position);
holder.titleTv.setText(downloads.get(position).getTitle());
Cursor cursor = downloadManager.query(
new DownloadManager.Query().setFilterById(item.getDownloadId()));
if (cursor != null && cursor.moveToNext()) {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_RUNNING
|| status == DownloadManager.STATUS_PENDING)
new Runnable() {
@Override
public void run() {
Cursor c = downloadManager.query(
new DownloadManager.Query()
.setFilterById(item.getDownloadId()));
float percent = 100;
if (c != null) {
if (c.moveToNext()) {
int downloadedBytes = c.getInt(c.getColumnIndex(
DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)
);
int totalBytes = c.getInt(c.getColumnIndex(
DownloadManager.COLUMN_TOTAL_SIZE_BYTES)
);
percent = totalBytes == 0 ? 0 : downloadedBytes / (float) (totalBytes / 100);
holder.percentTv.setText(String.valueOf(Math.round(percent)).concat("%"));
holder.progressLayout.setCurrentProgress(Math.round(percent));
}
c.close();
}
if (percent != 100)
holder.progressHandler.postDelayed(this, 1000);
}
}.run();
else {
if (status == DownloadManager.STATUS_SUCCESSFUL) {
holder.percentTv.setText("100%");
holder.progressLayout.setCurrentProgress(100);
} if (status == DownloadManager.STATUS_FAILED)
holder.percentTv.setText("Failed");
else
holder.progressLayout.setCurrentProgress(100);
if (!Utils.isFileExists(item.getFilepath()))
item.delete();
}
}
}
Here is crash log
Fatal Exception: java.lang.SecurityException: Requesting code from com.android.providers.downloads (with uid 10026) to be run in process my.package (with uid 10134)
at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1877)
at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1853)
at android.app.ContextImpl.createPackageContextAsUser(ContextImpl.java:2231)
at android.app.ContextImpl.createPackageContext(ContextImpl.java:2217)
at android.app.ActivityThread.installProvider(ActivityThread.java:4977)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4657)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2494)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1110)
at android.content.ContentResolver.query(ContentResolver.java:365)
at android.content.ContentResolver.query(ContentResolver.java:324)
at android.app.DownloadManager$Query.runQuery(DownloadManager.java:1262)
at android.app.DownloadManager.query(DownloadManager.java:1473)
at my.package.adapters.DownloadsAdapter$1.run(DownloadsAdapter.java:71)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5302)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
Can't figure out whats the crash is, and how to reproduce that crash. Hope to your help stackoverflow community.