diff --git a/android/android.iml b/android/android.iml
deleted file mode 100644
index 497788b0..00000000
--- a/android/android.iml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/android/app/AndroidManifest.xml b/android/app/AndroidManifest.xml
index 85ac1cd6..9a979d6b 100644
--- a/android/app/AndroidManifest.xml
+++ b/android/app/AndroidManifest.xml
@@ -2,14 +2,19 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.pushdemo">
+
+
-
-
+
+
-
-
-
-
-
-
-
-
@@ -76,61 +68,61 @@
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/android/app/build.gradle b/android/app/build.gradle
index ded6ae7b..d0d97f14 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -9,7 +9,7 @@ import com.android.build.OutputFile
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
- * `apply from: "react.gradle"` line.
+ * `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
@@ -26,7 +26,9 @@ import com.android.build.OutputFile
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
- * // The configuration property is in the format 'bundleIn${productFlavor}${buildType}'
+ * // The configuration property can be in the following formats
+ * // 'bundleIn${productFlavor}${buildType}'
+ * // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
@@ -53,11 +55,17 @@ import com.android.build.OutputFile
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
- * inputExcludes: ["android/**", "ios/**"]
+ * inputExcludes: ["android/**", "ios/**"],
+ *
+ * // override which node gets called and with what additional arguments
+ * nodeExecutableAndArgs: ["node"]
+ *
+ * // supply additional arguments to the packager
+ * extraPackagerArgs: []
* ]
*/
-apply from: "react.gradle"
+apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
@@ -72,7 +80,7 @@ def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
-def enableProguardInReleaseBuilds = true
+def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
@@ -90,9 +98,9 @@ android {
}
splits {
abi {
- enable enableSeparateBuildPerCPUArchitecture
- universalApk false // Also generate an universal APK
reset()
+ enable enableSeparateBuildPerCPUArchitecture
+ universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
@@ -100,7 +108,6 @@ android {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
- minifyEnabled true
}
}
sourceSets {
@@ -131,7 +138,14 @@ android {
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
- compile project(':jpush-react-native')
compile "com.android.support:appcompat-v7:23.0.1"
- compile "com.facebook.react:react-native:0.19.+"
+ compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':jpush-react-native')
+}
+
+// Run this once to be able to run the application with BUCK
+// puts all compile dependencies into folder libs for BUCK to use
+task copyDownloadableDepsToLibs(type: Copy) {
+ from configurations.compile
+ into 'libs'
}
diff --git a/android/app/react.gradle b/android/app/react.gradle
deleted file mode 100644
index 4b43bf91..00000000
--- a/android/app/react.gradle
+++ /dev/null
@@ -1,96 +0,0 @@
-import org.apache.tools.ant.taskdefs.condition.Os
-
-def config = project.hasProperty("react") ? project.react : [];
-
-def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
-def entryFile = config.entryFile ?: "index.android.js"
-
-// because elvis operator
-def elvisFile(thing) {
- return thing ? file(thing) : null;
-}
-
-def reactRoot = elvisFile(config.root) ?: file("../../")
-def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
-
-void runBefore(String dependentTaskName, Task task) {
- Task dependentTask = tasks.findByPath(dependentTaskName);
- if (dependentTask != null) {
- dependentTask.dependsOn task
- }
-}
-
-gradle.projectsEvaluated {
- // Grab all build types and product flavors
- def buildTypes = android.buildTypes.collect { type -> type.name }
- def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
-
- // When no product flavors defined, use empty
- if (!productFlavors) productFlavors.add('')
-
- productFlavors.each { productFlavorName ->
- buildTypes.each { buildTypeName ->
- // Create variant and source names
- def sourceName = "${buildTypeName}"
- def targetName = "${sourceName.capitalize()}"
- if (productFlavorName) {
- sourceName = "${productFlavorName}${targetName}"
- }
-
- // React js bundle directories
- def jsBundleDirConfigName = "jsBundleDir${targetName}"
- def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
- file("$buildDir/intermediates/assets/${sourceName}")
-
- def resourcesDirConfigName = "jsBundleDir${targetName}"
- def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
- file("$buildDir/intermediates/res/merged/${sourceName}")
- def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
-
- // Bundle task name for variant
- def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets"
-
- def currentBundleTask = tasks.create(
- name: bundleJsAndAssetsTaskName,
- type: Exec) {
- group = "react"
- description = "bundle JS and assets for ${targetName}."
-
- // Create dirs if they are not there (e.g. the "clean" task just ran)
- doFirst {
- jsBundleDir.mkdirs()
- resourcesDir.mkdirs()
- }
-
- // Set up inputs and outputs so gradle can cache the result
- inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
- outputs.dir jsBundleDir
- outputs.dir resourcesDir
-
- // Set up the call to the react-native cli
- workingDir reactRoot
-
- // Set up dev mode
- def devEnabled = !targetName.toLowerCase().contains("release")
- if (Os.isFamily(Os.FAMILY_WINDOWS)) {
- commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
- "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
- } else {
- commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
- "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
- }
-
- enabled config."bundleIn${targetName}" ?: targetName.toLowerCase().contains("release")
- }
-
- // Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
- currentBundleTask.dependsOn("merge${targetName}Resources")
- currentBundleTask.dependsOn("merge${targetName}Assets")
-
- runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
- runBefore("processX86${targetName}Resources", currentBundleTask)
- runBefore("processUniversal${targetName}Resources", currentBundleTask)
- runBefore("process${targetName}Resources", currentBundleTask)
- }
- }
-}
diff --git a/android/app/src/com/pushdemo/MainActivity.java b/android/app/src/com/pushdemo/MainActivity.java
index 26c67321..e7ca864f 100644
--- a/android/app/src/com/pushdemo/MainActivity.java
+++ b/android/app/src/com/pushdemo/MainActivity.java
@@ -1,64 +1,57 @@
package com.pushdemo;
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.KeyEvent;
-
-import com.facebook.react.LifecycleState;
-import com.facebook.react.ReactInstanceManager;
-import com.facebook.react.ReactRootView;
+import com.facebook.react.*;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
-import com.facebook.react.shell.MainReactPackage;
import java.lang.Override;
-import cn.jpush.reactnativejpush.JPushPackage;
-
-public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
-
- private ReactRootView mReactRootView;
- private ReactInstanceManager mReactInstanceManager;
- public static boolean isForeground = false;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mReactRootView = new ReactRootView(this);
- mReactInstanceManager = ReactInstanceManager.builder()
- .setApplication(getApplication())
- .setBundleAssetName("index.android.bundle")
- .setJSMainModuleName("react-native-android/index.android")
- .addPackage(new MainReactPackage())
- .addPackage(new JPushPackage())
- .setUseDeveloperSupport(BuildConfig.DEBUG)
- .setInitialLifecycleState(LifecycleState.RESUMED)
- .build();
- mReactRootView.startReactApplication(mReactInstanceManager, "PushDemoApp", null);
-
- setContentView(mReactRootView);
- }
+import cn.jpush.android.api.JPushInterface;
+
+public class MainActivity extends ReactActivity implements DefaultHardwareBackBtnHandler {
+
+ /**
+ * rn 0.29.0 以下版本,请使用此方法,并去掉 MainApplication 文件, 0.29.0 以上版本请去掉这些注释代码
+ * 注意改变其中的 JSMainModuleName 的路径(因为此版本适配了 rn 0.30.0, index.android.js 放在了项目目录下)
+ * 相应地,index.android.js 中 push_activity.js,set_activity.js的引用路径也要改变(参考 index.android.js)
+ */
+// private ReactRootView mReactRootView;
+// private ReactInstanceManager mReactInstanceManager;
+// private boolean SHUTDOWN_TOAST = false;
+// private boolean SHUTDOWN_LOG = false;
+
+// @Override
+// protected void onCreate(Bundle savedInstanceState) {
+// super.onCreate(savedInstanceState);
+// mReactRootView = new ReactRootView(this);
+// mReactInstanceManager = ReactInstanceManager.builder()
+// .setApplication(getApplication())
+// .setBundleAssetName("index.android.bundle")
+// .setJSMainModuleName("react-native-android/index.android")
+// .addPackage(new MainReactPackage())
+// .addPackage(new JPushPackage(SHUTDOWN_TOAST, SHUTDOWN_LOG))
+// .setUseDeveloperSupport(BuildConfig.DEBUG)
+// .setInitialLifecycleState(LifecycleState.RESUMED)
+// .build();
+// mReactRootView.startReactApplication(mReactInstanceManager, "PushDemoApp", null);
+//
+// setContentView(mReactRootView);
+// }
@Override
- public void invokeDefaultOnBackPressed() {
- super.onBackPressed();
+ protected String getMainComponentName() {
+ return "PushDemoApp";
}
@Override
protected void onPause() {
super.onPause();
- isForeground = false;
- if (mReactInstanceManager != null) {
- mReactInstanceManager.onPause();
- }
+ JPushInterface.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
- isForeground = true;
- if (mReactInstanceManager != null) {
- mReactInstanceManager.onResume(this, this);
- }
+ JPushInterface.onResume(this);
}
@Override
@@ -66,21 +59,4 @@ protected void onDestroy() {
super.onDestroy();
}
- @Override
- public void onBackPressed() {
- if (mReactInstanceManager != null) {
- mReactInstanceManager.onBackPressed();
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
- mReactInstanceManager.showDevOptionsDialog();
- return true;
- }
- return super.onKeyUp(keyCode, event);
- }
}
diff --git a/android/app/src/com/pushdemo/MainApplication.java b/android/app/src/com/pushdemo/MainApplication.java
new file mode 100644
index 00000000..50870ede
--- /dev/null
+++ b/android/app/src/com/pushdemo/MainApplication.java
@@ -0,0 +1,43 @@
+package com.pushdemo;
+
+import android.app.Application;
+
+import com.facebook.react.ReactApplication;
+import com.facebook.react.ReactNativeHost;
+import com.facebook.react.ReactPackage;
+import com.facebook.react.shell.MainReactPackage;
+
+import java.util.Arrays;
+import java.util.List;
+
+import cn.jpush.reactnativejpush.JPushPackage;
+
+public class MainApplication extends Application implements ReactApplication {
+
+ private boolean SHUTDOWN_TOAST = false;
+ private boolean SHUTDOWN_LOG = false;
+
+ private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
+
+ @Override
+ protected boolean getUseDeveloperSupport() {
+ return BuildConfig.DEBUG;
+ }
+
+
+ @Override
+ protected List getPackages() {
+ return Arrays.asList(
+ new MainReactPackage(),
+ new JPushPackage(SHUTDOWN_TOAST, SHUTDOWN_LOG)
+ );
+ }
+ };
+
+ @Override
+ public ReactNativeHost getReactNativeHost() {
+ return mReactNativeHost;
+ }
+
+
+}
diff --git a/android/build.gradle b/android/build.gradle
index f1329100..46047bda 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -16,5 +16,9 @@ allprojects {
repositories {
mavenLocal()
jcenter()
+ maven {
+ // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
+ url "$rootDir/../node_modules/react-native/android"
+ }
}
}
diff --git a/react-native-android/index.android.js b/index.android.js
similarity index 92%
rename from react-native-android/index.android.js
rename to index.android.js
index 1a104376..4f7ec27c 100644
--- a/react-native-android/index.android.js
+++ b/index.android.js
@@ -5,8 +5,8 @@
import React from 'react';
import ReactNative from 'react-native';
-import PushActivity from './push_activity';
-import SetActivity from './set_activity';
+import PushActivity from './react-native-android/push_activity';
+import SetActivity from './react-native-android/set_activity';
const {
AppRegistry,
diff --git a/package.json b/package.json
index 30345225..48c40728 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
- "jpush-react-native": "0.0.11",
+ "jpush-react-native": "^0.1.1",
"react-native": "^0.19.0"
}
}
diff --git a/react-native-android/push_activity.js b/react-native-android/push_activity.js
index 9da4ed9f..09f838ed 100644
--- a/react-native-android/push_activity.js
+++ b/react-native-android/push_activity.js
@@ -32,8 +32,8 @@ export default class PushActivity extends React.Component {
deviceId: 'DeviceId',
version: 'Version',
pushMsg: 'PushMessage',
- registrationId: 'registrationId'
- }
+ registrationId: 'registrationId',
+ };
this.jumpSetActivity = this.jumpSetActivity.bind(this);
this.onInitPress = this.onInitPress.bind(this);
@@ -79,15 +79,19 @@ export default class PushActivity extends React.Component {
}
- componentDidMount() {
+ componentDidMount() {
JPushModule.addReceiveCustomMsgListener((message) => {
this.setState({pushMsg: message});
});
- JPushModule.addReceiveNotificationListener((message) => {
- console.log("receive notification: " + message);
+ JPushModule.addReceiveNotificationListener((map) => {
+ console.log("alertContent: " + map.alertContent);
+ console.log("extras: " + map.extras);
+ // var extra = JSON.parse(map.extras);
+ // console.log(extra.key + ": " + extra.value);
});
JPushModule.addReceiveOpenNotificationListener((map) => {
console.log("Opening notification!");
+ this.props.navigator.push({name: "pushActivity"});
})
}
diff --git a/react-native-android/set_activity.js b/react-native-android/set_activity.js
index 4729aa67..66b4c177 100644
--- a/react-native-android/set_activity.js
+++ b/react-native-android/set_activity.js
@@ -3,6 +3,7 @@
import React from 'react';
import ReactNative from 'react-native';
const {
+ BackAndroid,
Text,
View,
TextInput,
@@ -28,6 +29,17 @@ export default class SetActivity extends React.Component {
this.setCustomStyle = this.setCustomStyle.bind(this);
}
+ componentDidMount() {
+ BackAndroid.addEventListener('hardwareBackPress', () => {
+ const navigator = this.props.navigator;
+ if (navigator.getCurrentRoutes().length > 1) {
+ navigator.pop();
+ return true;
+ }
+ return false;
+ });
+ }
+
setTag() {
if (this.state.tag !== undefined) {
/*