-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Android-NotificationSkip——Just Kiss Principle | ||
== | ||
|
||
## Pro background | ||
|
||
**读者平时项目涉及到推送的时候,考虑到开发成本等各个技术原因,基本上用的都是第三方现有的sdk。本lib针对的是:收到通知消息后,用户点击通知栏跳转到目标界面以及其他后续动作,始终会处理这块的跳转业务逻辑,心中会产生无数个翻腾.** | ||
|
||
--- | ||
|
||
## Actual Scene | ||
|
||
|
||
例如:读者某一个项目使用了小米推送服务,当receiver中的onNotificationMessageClicked(params) 方法(即是用户点击通知栏进行界面跳转的时候)调用的时候,app本身进程有两种情况:1、app正在运行;2、app已经退出。对于第一种情况 ,直接将参数传入Intent并打开对应的activity即可;但是对于第二种相对而言就复杂了许多了,如果app已经退出,而要打开的目标activity中的某些操作是需要依赖app初始化的,这些初始化操作是在app启动过程中进行的,并且如果直接跳转到目标界面,当用户按了返回键之后,由于activity任务栈只存在一个,就会退出app,然后真正想要的效果是:返回到上一个界面。 | ||
|
||
|
||
## Some Tips | ||
|
||
|
||
|
||
- 对于判断app本身是处于前台或者后台,泡网上的日子一哥们已经开源出来一套比较牛逼的方法了,链接地址忘了....,本lib是采用的是自己维护一个Stack来管理所有的activity,目的是兼容性相对而言要好一些,并且到时候对一些方法做额外开放! | ||
|
||
|
||
|
||
--- | ||
|
||
|
||
## Use Code | ||
|
||
|
||
前台所有activity集成NSBaseActivity ---------------------->设计不是很合理 见谅了 | ||
|
||
在你处理跳转业务方法的地方加上 | ||
NSSkipClient.get().handleNotificationClickLogic(context, targetIntent); | ||
其中targetIntent不需要在去设置额外flag,你仅仅需要添加一些你想要携带的参数 | ||
在MainActivity onCreate中添加 NSSkipClient.get().listeneIn(this); ps:MainActivity 作为一个common bus 呵呵~~ | ||
|
||
在TargetActivity onCreate中数据获取判断,onNewIntent()及时刷新界面 | ||
|
||
TargetActivity 在功能清单文件中声明启动模式为singleTask .just recommend | ||
|
||
|
||
## Other | ||
|
||
读者认为 写得tm太菜了 就一时无聊 !! 越看真心不够优雅 | ||
|
||
其他问题可以通过邮件互相沟通 互相学习 [email protected] | ||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "cn.andaction.notificationskip" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile files('libs/MiPush_SDK_Client_2_2_21.jar') | ||
compile project(':nslib') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.andaction.notificationskip; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="cn.andaction.notificationskip" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
<uses-permission android:name="android.permission.GET_TASKS" /> | ||
<!-- the following 2 com.xiaomi.mipushdemo should be changed to your package name --> | ||
<permission | ||
android:name="cn.andaction.notificationskip.permission.MIPUSH_RECEIVE" | ||
android:protectionLevel="signature" /> | ||
|
||
<uses-permission android:name="cn.andaction.notificationskip.permission.MIPUSH_RECEIVE" /> | ||
<uses-permission android:name="android.permission.VIBRATE" /> | ||
|
||
<application | ||
android:name=".CApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".SplashActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".MainActivity"/> | ||
<activity android:name=".TargetActivity" | ||
android:launchMode="singleTask"/> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<service | ||
android:name="com.xiaomi.push.service.XMPushService" | ||
android:enabled="true" | ||
android:process=":pushservice" /> | ||
<service | ||
android:name="com.xiaomi.mipush.sdk.PushMessageHandler" | ||
android:enabled="true" | ||
android:exported="true" /> | ||
<service android:enabled="true" | ||
android:name="com.xiaomi.mipush.sdk.MessageHandleService" /> | ||
|
||
<receiver | ||
android:name=".MessageReceiver" | ||
android:exported="true" > | ||
<intent-filter> | ||
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /> | ||
</intent-filter> | ||
<intent-filter> | ||
<action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /> | ||
</intent-filter> | ||
<intent-filter> | ||
<action android:name="com.xiaomi.mipush.ERROR" /> | ||
</intent-filter> | ||
</receiver> | ||
<receiver | ||
android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver" | ||
android:exported="true" > | ||
<intent-filter> | ||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> | ||
|
||
<category android:name="android.intent.category.DEFAULT" /> | ||
</intent-filter> | ||
</receiver> | ||
<receiver | ||
android:name="com.xiaomi.push.service.receivers.PingReceiver" | ||
android:exported="false" | ||
android:process=":pushservice" > | ||
<intent-filter> | ||
<action android:name="com.xiaomi.push.PING_TIMER" /> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cn.andaction.notificationskip; | ||
|
||
import android.app.Application; | ||
|
||
/** | ||
* User: Geek_Soledad([email protected]) | ||
* Date: 2016-02-26 | ||
* Time: 11:50 | ||
* Description: ..... | ||
*/ | ||
public class CApplication extends Application { | ||
public static CApplication mGlobalContext; | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
this.mGlobalContext = this; | ||
PushEngine.newInstance().registerPush(true); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cn.andaction.notificationskip; | ||
|
||
import android.os.Bundle; | ||
|
||
import cn.andaction.nslib.NSBaseActivity; | ||
import cn.andaction.nslib.NSSkipClient; | ||
|
||
public class MainActivity extends NSBaseActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
NSSkipClient.get().listeneIn(this); | ||
|
||
PushEngine.newInstance().checkManifest(); | ||
PushEngine.newInstance().getRegisterId(); | ||
} | ||
} |