搜索
您的当前位置:首页正文

记:继上一篇极光推送,透传

来源:知库网
废话不多说,直接开始我们的透传部分~

1.在Manifest文件中,注册一个广播,用来接收推送(极光推送官方也带一个,我是直接在这上面修改的)

<receiver    
    android:name="com.risenbsy.tianxian.util.MyReceiver"    
    android:enabled="true"    
    android:exported="false">    
   <intent-filter>
       <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  用户接收SDK通知栏信息的intent-->
       <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required  用户打开自定义通知栏的intent-->
       <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <!--Optional 用户接受Rich Push Javascript 回调函数的intent-->
       <action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收网络变化 连接/断开 since 1.6.3 -->
       <category android:name="com.risenbsy.tianxian" />
   </intent-filter>
</receiver>

2.在自定义的广播器(我这里叫MyReceiver)中的打开通知方法中写(下面是举个例子)

String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
try {    
          JSONObject object = new JSONObject(extras);    
          messageType = object.getString("messageType");   
          interfaceName = object.getString("interface");    
          orderId = object.getString("orderid");    
          orderType = object.getString("ordertype");   
          orderStatus = object.getString("orderStatus");
    } catch (JSONException e) {    
      e.printStackTrace();
     }
   if (messageType.equals("1")) {    
        Intent i = new Intent(context, OrderDetailActivity.class);    
        bundle.putString("orderNo", orderId);   
        bundle.putString("orderType", orderType);   
        bundle.putString("type", orderStatus);   
        i.putExtras(bundle);    
        //这句话的意思是,如果有多个通知,多次点击,依然只会打开一个页面
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);                                
        context.startActivity(i);} else {
        //想要跳转的界面
        Intent i = new Intent(context, MyMessageActivity.class); 
        i.putExtra("messageType", messageType);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);  
        context.startActivity(i);
   }

3.接下来就是你在(我这里是MyMessageActivity.class)文件中通过intent接收值,并进行一系列的操作了

4.※※※当你当前登录的账号,想要退出时候,是不应该再能接收到你的账号的消息,那么需要进行几个操作:

JPushInterface.clearAllNotifications(getApplicationContext());

JPushInterface.setAlias(SystemSettingActivity.this, "", new TagAliasCallback() {   
 @Override    public void gotResult(int i, String s, Set<String> set) {    }
});

至此,透传部分分享完毕啦

期待和你共同成为进步路上的小伙伴❀

Top