2

I am developing an android app using react-native, i want to use local push notification for that, like whenever i click on button, push notification should create. how can i do this? someone please suggest me something.

7
  • You can use react-native-fcm or react-native-push-notification for local push notifications as well as remote notifications. Commented Mar 27, 2017 at 9:03
  • Thank you @Hariks but i am not understanding how to use the code. where i should call the fuctions. Commented Mar 27, 2017 at 9:09
  • in 'usage' they have given some code that i am not understanding, where to write that code? Commented Mar 27, 2017 at 9:10
  • React native part or the native part where you add the package? Commented Mar 27, 2017 at 9:13
  • react-native part Commented Mar 27, 2017 at 9:16

3 Answers 3

1

You could try this with react-native-push-notification

import PushNotification from 'react-native-push-notification';

scheduleNotfication() { 
 PushNotification.localNotificationSchedule({ 
 message: "My Notification Message", // message 
 date: new Date(Date.now() + (60 * 1000)) // your required time 
 }); 
}  

Button

<Button title="title of button" onPress ={this.scheduleNotfication() } > 
<Text>show</Text> 
</Button>
Sign up to request clarification or add additional context in comments.

Comments

1
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
 TouchableHighlight
 } from 'react-native';

import PushNotification from 'react-native-push-notification';

export default class pn extends Component {
  scheduleNotfication() { 
PushNotification.localNotificationSchedule({ 
message: "My Notification Message", // message 
date: new Date(Date.now() + (60 * 1000)) // your required time 
}); 
}
  render() {
    return (
      <View>


<TouchableHighlight onPress ={this.scheduleNotfication.bind(this) } >
<Text>show</Text> 
</TouchableHighlight>

      </View>
    );
  }
}


AppRegistry.registerComponent('pn', () => pn);

This is working perfect and getting local Push Notification for certain time.

Comments

0

You can also try

react-native-notifications

It helps you in local as well as a remote push notification.

1.Remote (push) notifications

2.Local notifications

3.Background/Managed notifications (notifications that can be cleared from the server, like Facebook messenger and Whatsapp web)

4.PushKit API (for VoIP and other background messages)

5.Interactive notifications (allows you to provide additional functionality to your users outside of your application such as action buttons)

Code snippets -->

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
 TouchableHighlight
 } from 'react-native';


import {NotificationsAndroid} from 'react-native-notifications';

export default class pushLocalNotification extends Component {
  get_Local_Notfication() { 
    NotificationsAndroid.localNotification({
      title: "Local notification",
      body: "This notification was generated by the app!",
      extra: "data"
    });
  }
  render() {
    return (
      <View>    
           <TouchableHighlight onPress =
                    {this.get_Local_Notfication.bind(this) } >
              <Text>show</Text> 
           </TouchableHighlight>
      </View>
    );
  }
}


AppRegistry.registerComponent('pushLocalNotification', () => 
    pushLocalNotification);

This is working perfectly for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.