标签:
极光推送
public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();System.out.println("应用创建啦....");JPushInterface.setDebugMode(true);JPushInterface.init(this);}public void doSomething() {System.out.println("do something...");}}
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);MyApplication application = (MyApplication) getApplication();application.doSomething();}
public class PushReceiver extends BroadcastReceiver {private static final String TAG = "PushReceiver";@Overridepublic void onReceive(Context context, Intent intent) {Bundle bundle = intent.getExtras();Log.d(TAG, "onReceive - " + intent.getAction());if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {System.out.println("收到了自定义消息。消息内容是:"+ bundle.getString(JPushInterface.EXTRA_MESSAGE));// 自定义消息不会展示在通知栏,完全要开发者写代码去处理} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {System.out.println("收到了通知");// 在这里可以做些统计,或者做些其他工作} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {System.out.println("用户点击打开了通知");// 在这里可以自己写代码去定义用户点击后的行为String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);System.out.println("附加信息:" + extra);try {JSONObject jo = new JSONObject(extra);String url = jo.getString("url");System.out.println("url:" + url);// 跳浏览器加载网页} catch (JSONException e) {e.printStackTrace();}}}}
标签:
原文地址:http://www.cnblogs.com/liuyu0529/p/4919342.html