找传奇、传世资源到传世资源站!

android 极光推送demo

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

package jg.demo.com.jiguangtest;import android.app.AlertDialog;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.support.v4.content.LocalBroadcastManager;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import cn.jpush.android.api.JPushInterface;import jg.demo.com.jiguangtest.push.ExampleUtil;public class MainActivity extends AppCompatActivity { private MessageReceiver mMessageReceiver; public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION"; public static final String KEY_TITLE = "title"; public static final String KEY_MESSAGE = "message"; public static final String KEY_EXTRAS = "extras"; public static boolean isForeground = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = this.getIntent().getExtras(); if (bundle != null) { String message = bundle.getString("cn.jpush.android.ALERT"); new AlertDialog.Builder(MainActivity.this).setTitle("消息").setMessage(message) .setPositiveButton("确定", null).show(); } setContentView(R.layout.activity_main); JPushInterface.setDebugMode(true); JPushInterface.init(this); registerMessageReceiver(); } public void registerMessageReceiver() { mMessageReceiver = new MessageReceiver(); IntentFilter filter = new IntentFilter(); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); filter.addAction(MESSAGE_RECEIVED_ACTION); LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter); } public class MessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) { String messge = intent.getStringExtra(KEY_MESSAGE); String extras = intent.getStringExtra(KEY_EXTRAS); StringBuilder showMsg = new StringBuilder(); showMsg.append(KEY_MESSAGE " : " messge "\n"); if (!ExampleUtil.isEmpty(extras)) { showMsg.append(KEY_EXTRAS " : " extras "\n"); } setCostomMsg(showMsg.toString()); } } catch (Exception e){ } } } private void setCostomMsg(String msg){ new AlertDialog.Builder(MainActivity.this).setTitle("消息").setMessage(msg) .setPositiveButton("确定", null).show(); }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复