一严衬、添加依賴
//極光推送
compile 'cn.jiguang.sdk:jpush:3.0.0'
compile 'cn.jiguang.sdk:jcore:1.0.0'
二、配置參數(shù)
//defaultConfig{
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "501e0f31b4e163e1", //JPush上注冊的包名對應(yīng)的appkey.
JPUSH_CHANNEL : "developer-default", //暫時填寫默認值即可.
}
三笆呆、配置清單文件
1.添加必要的權(quán)限
2.注冊廣播接受者
<!-- User defined. 用戶自定義的廣播接收器 -->
<receiver
android:name=".bookstore.receiver.PushReceiver"
android:enabled="true">
<intent-filter>
<!-- Required 用戶注冊SDK的intent -->
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
<!-- Required 用戶接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
<!-- Required 用戶接收SDK通知欄信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
<!-- Required 用戶打開自定義通知欄的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
<!-- 接收網(wǎng)絡(luò)變化 連接/斷開 since 1.6.3 -->
<action android:name="cn.jpush.android.intent.CONNECTION"/>
<category android:name="com.laikan.reader"/>
</intent-filter>
</receiver>
四请琳、創(chuàng)建Receiver類
public class PushReceiver extends BroadcastReceiver{
private static final String TAG = "PushReceiver";
private NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("lyt","receiver called");
if (null == nm) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
Bundle bundle = intent.getExtras();
// Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
Log.d(TAG, "JPush用戶注冊成功");
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "接受到推送下來的自定義消息");
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "接受到推送下來的通知");
receivingNotification(context,bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Log.d(TAG, "用戶點擊打開了通知");
// openNotification(context,bundle);
openLaikan(context);
} else {
Log.d(TAG, "Unhandled intent - " + intent.getAction());
}
}
五、在Application中初始化Jpush
JPushInterface.init(this);
JPushInterface.setDebugMode(true); // 極光推送 設(shè)置開啟日志,發(fā)布時請關(guān)閉日志
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者