Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Action not performing the task #210

Open
Ahmad44452 opened this issue Feb 6, 2024 · 0 comments
Open

Background Action not performing the task #210

Ahmad44452 opened this issue Feb 6, 2024 · 0 comments

Comments

@Ahmad44452
Copy link

I am trying to build an app for android, in which user can set time-slots and then according to those time-slots the wallpaper change throughout the day. One of the task would be to change the wallpaper in the background. For now, I have the following function that triggers on the click of the button. This function aims to set an image as the phones wallpaper after 15 seconds. It works completely fine, if the app is in foreground or is closed but available in recent apps.

  const setWallpaper = async () => {
    await BackgroundService.start(
      async () => {
        console.log('Starting Background Service');
        await delay(15000);
        console.log('Setting Wallpaper');
        await new Promise(resolve => {
          ManageWallpaper.setWallpaper(
            {
              uri: 'file:///storage/emulated/0/DCIM/Snapchat/Snapchat-118465363.jpg',
            },
            (res: any) => {
              console.log(res);
              resolve(res);
            },
            TYPE.HOME,
          );
        });

        console.log('Wallpaper set successfully');
      },
      {
        taskName: 'Set Wallpaper',
        taskTitle: 'ExampleTask title',
        taskDesc: 'ExampleTask description',
        taskIcon: {
          name: 'ic_launcher',
          type: 'mipmap',
        },
        color: '#ff00ff',
        linkingURI: 'yourSchemeHere://chat/jane',
      },
    );
    await BackgroundService.updateNotification({
      taskDesc: 'New ExampleTask description',
    }); 
  };

However, if I completely close the app (remove it from recent apps), the function works just partially. The string Starting Background Service and Setting Wallpaper before and after the delay are logged successfully. After this the ManageWallpaper.setWallpaper tries to change the wallpaper (ManageWallpaper class comes from this library). But neither does the wallpaper change nor the Wallpaper set successfully is logged and just the following two strings are logged.

BUNDLE  ./index.js 

WARN  No task registered for key Set Wallpaper1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant