How to get broadcast of new media in gallery?

+1 vote
asked Sep 13, 2017 by adrian-le-roy-devezi

I am trying to get notified of a new picture or video added to the phone gallery. I would need to obtain the new media's URI. The purpose is so i can automatically back it up. So i need a register that is set in the background to continuously listen or check for new media added to the gallery, and captures the Uri. This used to be done with a broadcast receiver such as:


        <!-- <action android:name="" /> -->
        <action android:name="android.hardware.action.NEW_PICTURE" />

        <data android:mimeType="image/*" />

However this was deprecated in API level 24. I target API 21-26. Can someone show me how to do this with JobSchedulers like android docs say too?

1 Answer

+1 vote
answered Sep 23, 2017 by amjad-khan

In API level 23 above Job scheduling is been introduce to perform the task

So I am placing sample of Job Scheduling which can help you

public class JobSchedulerService extends JobService {

    private Context mContext;
    private static final int ASJOBSERVICE_JOB_ID = 999;

    // A pre-built JobInfo we use for scheduling our job.
    private static JobInfo JOB_INFO = null;

    public static int a(Context context) {
        int schedule = ((JobScheduler) context.getSystemService(JobScheduler.class)).schedule(JOB_INFO);
        Log.i("PhotosContentJob", "JOB SCHEDULED!");
        return schedule;

    // Schedule this job, replace any existing one.
    public static void scheduleJob(Context context) {
        if (JOB_INFO != null) {
        } else {
            JobScheduler js = context.getSystemService(JobScheduler.class);
            JobInfo.Builder builder = new JobInfo.Builder(ASJOBSERVICE_JOB_ID,
                    new ComponentName("YOUR_PACKAGE_NAME", JobSchedulerService.class.getName()));
            builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 1));
            builder.addTriggerContentUri(new JobInfo.TriggerContentUri(MediaStore.Images.Media.INTERNAL_CONTENT_URI, 1));
            JOB_INFO =;

    @RequiresApi(api = Build.VERSION_CODES.N)
    public boolean onStartJob(final JobParameters params) {
        mContext = this;
        // Did we trigger due to a content change?
        if (params.getTriggeredContentAuthorities() != null) {
            if (params.getTriggeredContentUris() != null) {
                // If we have details about which URIs changed, then iterate through them
                // and collect either the ids that were impacted or note that a generic
                // change has happened.
                ArrayList<String> ids = new ArrayList<>();
                for (Uri uri : params.getTriggeredContentUris()) {
                    if (uri != null) {
                        Handler handler = new Handler();
               Runnable() {
                            public void run() {
                                //Perform your task here
                jobFinished(params, true); // see this, we are saying we just finished the job
                // We will emulate taking some time to do this work, so we can see batching happen.
        return true;

    public boolean onStopJob(JobParameters params) {
        return false;


In Manifest File

    android:permission="android.permission.BIND_JOB_SERVICE" />

In Your which ever your launcher file

    protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.