当我添加时,我试图在画廊中获取所有媒体的Uri。例如。用途拍照。我自动收到包含Uri的意图。我定位的是Apis 21-26,Android在不使用JobObservers的情况下删除了在Api 25中执行此操作的功能。我不知道如何使用JobObserver执行此操作。有人可以帮忙吗?
答案 0 :(得分:1)
要与jobcheduler一起使用,请使用这些内容uris
JobInfo.Builder builder = new JobInfo.Builder(ASJOBSERVICE_JOB_ID, new ComponentName("co.intellidev.storj", JobSchedulerService.class.getName()));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, flag));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.INTERNAL_CONTENT_URI, flag));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, flag));
builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Video.Media.INTERNAL_CONTENT_URI, flag));
答案 1 :(得分:0)
首先,FileOberver是一种内存杀手方法。考虑大量文件。相反,ContentObserver似乎是一种更好的方法。
getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, true,
new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Log.d("your_tag","Internal Media has been changed");
super.onChange(selfChange);
Long timestamp = readLastDateFromMediaStore(context, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
// comapare with your stored last value and do what you need to do
}
}
);
getContentResolver().registerContentObserver(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true,
new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Log.d("your_tag","External Media has been changed");
super.onChange(selfChange);
Long timestamp = readLastDateFromMediaStore(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// comapare with your stored last value and do what you need to do
}
}
);
private Long readLastDateFromMediaStore(Context context, Uri uri) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, "date_added DESC");
PhotoHolder media = null;
Long dateAdded =-1;
if (cursor.moveToNext()) {
Long dateAdded = cursor.getLong(cursor.getColumnIndexOrThrow(MediaColumns.DATE_ADDED));
}
cursor.close();
return dateAdded;
}