Java tutorial
package com.BeeFramework.service; /* * ______ ______ ______ * /\ __ \ /\ ___\ /\ ___\ * \ \ __< \ \ __\_ \ \ __\_ * \ \_____\ \ \_____\ \ \_____\ * \/_____/ \/_____/ \/_____/ * * * Copyright (c) 2013-2014, {Bee} open source community * http://www.bee-framework.com * * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import com.baidu.android.pushservice.PushConstants; import org.json.JSONException; import org.json.JSONObject; public class PushMessageReceiver extends BroadcastReceiver { private SharedPreferences shared; private SharedPreferences.Editor editor; /** * * * @param context * Context * @param intent * intent */ @Override public void onReceive(final Context context, Intent intent) { shared = context.getSharedPreferences("userInfo", 0); editor = shared.edit(); if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) { //?? // String message = intent.getExtras().getString( // PushConstants.EXTRA_PUSH_MESSAGE_STRING); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // // //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_MESSAGE); // responseIntent.putExtra(SquaredActivity.EXTRA_MESSAGE, message); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); //?? //:PushManager.startWork()PushConstants.METHOD_BIND } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVE)) { //? final String method = intent.getStringExtra(PushConstants.EXTRA_METHOD); //?,???bind??bind,??startWork final int errorCode = intent.getIntExtra(PushConstants.EXTRA_ERROR_CODE, PushConstants.ERROR_SUCCESS); // final String content = new String(intent.getByteArrayExtra(PushConstants.EXTRA_CONTENT)); //??,?demo? // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_RESPONSE); // responseIntent.putExtra(SquaredActivity.RESPONSE_METHOD, method); // responseIntent.putExtra(SquaredActivity.RESPONSE_ERRCODE, // errorCode); // responseIntent.putExtra(SquaredActivity.RESPONSE_CONTENT, content); // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // context.startActivity(responseIntent); if (errorCode == 0) { String appid = ""; String channelid = ""; String userid = ""; try { JSONObject jsonContent = new JSONObject(content); JSONObject params = jsonContent.getJSONObject("response_params"); appid = params.getString("appid"); channelid = params.getString("channel_id"); userid = params.getString("user_id"); editor.putString("UUID", userid); editor.commit(); } catch (JSONException e) { } } //?? } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVER_NOTIFICATION_CLICK)) { // String content = intent // .getStringExtra(PushConstants.EXTRA_NOTIFICATION_CONTENT); // // Intent responseIntent = null; // responseIntent = new Intent(SquaredActivity.ACTION_PUSHCLICK); // // // responseIntent.setClass(context, SquaredActivity.class); // responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // // //??CUSTOM_KEY????key // String customContentString = intent.getExtras().getString("content"); // responseIntent.putExtra(SquaredActivity.CUSTOM_CONTENT, customContentString); // // context.startActivity(responseIntent); } } }