Skip to content

Instantly share code, notes, and snippets.

@WilliamAnputra
Created September 8, 2017 18:56
Show Gist options
  • Save WilliamAnputra/38c35dd08b201504bae5e42eae59b09a to your computer and use it in GitHub Desktop.
Save WilliamAnputra/38c35dd08b201504bae5e42eae59b09a to your computer and use it in GitHub Desktop.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "bamms.bamms"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
manifestPlaceholders = [
'appAuthRedirectScheme': 'bamms',
onesignal_app_id: '42ded2df-3fdc-49b7-8f46-07e9bd608733',
onesignal_google_project_number: '923442899965'
]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "8g"
}
}
task exponentPrebuildStep(type: Exec) {
workingDir '../../'
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
} else {
commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
}
}
preBuild.dependsOn exponentPrebuildStep
repositories{
flatDir{
dirs 'libs'
}
mavenLocal()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile project(':react-native-onesignal')
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile('host.exp.exponent:expoview:20.0.0@aar') {
exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
exclude group: 'com.facebook.android', module: 'audience-network-sdk'
exclude group: 'io.nlopez.smartlocation', module: 'library'
transitive = true;
}
compile ('com.facebook.android:facebook-android-sdk:4.7.0') {
exclude module: 'bolts-android'
}
compile('com.facebook.android:audience-network-sdk:4.19.0') {
exclude module: 'play-services-ads'
}
compile('io.nlopez.smartlocation:library:3.2.11') {
transitive = false
}
}
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import OneSignal from "react-native-onesignal";
export default class App extends React.Component {
componentWillMount() {
OneSignal.setSubscription(true);
OneSignal.enableSound(true);
OneSignal.addEventListener("received", this.onReceived);
OneSignal.addEventListener("opened", this.onOpened);
OneSignal.addEventListener("registered", this.onRegistered);
OneSignal.addEventListener("ids", this.onIds);
}
componentWillUnmount() {
OneSignal.removeEventListener("received", this.onReceived);
OneSignal.removeEventListener("opened", this.onOpened);
OneSignal.removeEventListener("registered", this.onRegistered);
OneSignal.removeEventListener("ids", this.onIds);
}
onReceived(notification) {
console.log("Notification received: ", notification);
}
onOpened(openResult) {
console.log("Message: ", openResult.notification.payload.body);
console.log("Data: ", openResult.notification.payload.additionalData);
console.log("isActive: ", openResult.notification.isAppInFocus);
console.log("openResult: ", openResult);
}
onRegistered(notifData) {
console.log("Device had been registered for push notifications!", notifData);
}
onIds(device) {
console.log("Device info: ", device);
}
render() {
return <View style={styles.container}>
<Text>
Open up App.js to start working on your
app!
</Text>
<Text>
Changes you make will automatically
reload.
</Text>
<Text>
Shake your phone to open the developer
menu.
</Text>
</View>;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Do not set onesignal_app_id here, it will be set in the app project.
// Leave onesignal_google_project_number as it is now pulled from the dashboard.
manifestPlaceholders = [onesignal_app_id: "",
onesignal_google_project_number: "REMOTE"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.react:react-native:+'
compile 'com.onesignal:OneSignal:3.+@aar'
compile 'com.google.android.gms:play-services-gcm:9.8.0'
compile 'com.google.android.gms:play-services-analytics:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
testCompile 'junit:junit:4.12'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment