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

How can i open app on click on the notification? #215

Open
AruAram opened this issue Mar 21, 2024 · 0 comments
Open

How can i open app on click on the notification? #215

AruAram opened this issue Mar 21, 2024 · 0 comments

Comments

@AruAram
Copy link

AruAram commented Mar 21, 2024

Hey guys, I need to open the app after I click on the notification. Now it doesn't do anything.

My xml code

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter android:label="filter_react_native"> 
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="yourSchemeHere" />
        </intent-filter>
      </activity>
    </application>
</manifest>

my JSX code

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import BackgroundService from 'react-native-background-actions';

const sleep = (time:number) => new Promise<void>((resolve) => setTimeout(() => resolve(), time));

const veryIntensiveTask = async (taskDataArguments:any) => {
    console.log("in intensive task");
    const { delay } = taskDataArguments;
    await new Promise( async (resolve) => {
        for (let i = 0; BackgroundService.isRunning(); i++) {
            const date = `${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`;
            console.log(`${i} => ${date}`); 
            await sleep(delay);
        }
    });
};

const options = {
    taskName: 'Example',
    taskTitle: 'ExampleTask title',
    taskDesc: 'ExampleTask description',
    taskIcon: {
        name: 'ic_launcher',
        type: 'mipmap',
    },
    color: '#ff00ff',
    linkingURI: 'yourSchemeHere://chat/jane', 
    parameters: {
        delay: 1000,
    },
};

export default function Background(){
  const startBackgoundJob=async ()=>{
      await BackgroundService.start(veryIntensiveTask, options);
      console.log("background service started");
  };

  const updateBackgroundJob=async ()=>{
      await BackgroundService.updateNotification({taskDesc: 'New ExampleTask description'}); 
      console.log("background service updated");
  };
  const stopBackgroundJob=async ()=>{
      await BackgroundService.stop();
      console.log("background service stopped");
  };
  return(
      <View style={{flex:1,display:"flex",justifyContent:"center",alignItems:"center"}}>
          <Button title="start background job" onPress={startBackgoundJob}/>
          <Button title="update background job" onPress={updateBackgroundJob}/>
          <Button title="stop background job" onPress={stopBackgroundJob}/>
      </View>
  )
}

Please let me know if you know how i can do it.

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