本文整理匯總了Java中cn.jpush.android.api.JPushInterface類的典型用法代碼示例。如果您正苦於以下問題:Java JPushInterface類的具體用法?Java JPushInterface怎麽用?Java JPushInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JPushInterface類屬於cn.jpush.android.api包,在下文中一共展示了JPushInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMessage
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
private MyMessage getMessage(Bundle bundle){
MyMessage message = new MyMessage();
message.setIsScanned(0);
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
message.setNotifyId(String.valueOf(bundle.getInt(key)));
}else if(key.equals(JPushInterface.EXTRA_ALERT)){
message.setAlert(bundle.getString(key));
} else if (key.equals(JPushInterface.EXTRA_MSG_ID)) {
message.setMsgId(bundle.getString(key));
} else if (key.equals(JPushInterface.EXTRA_ALERT_TYPE)) {
message.setType(bundle.getString(key));
}else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
Log.d(TAG, "This message has no Extra data");
continue;
}
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
Iterator<String> it = json.keys();
while (it.hasNext()) {
String myKey = it.next().toString();
if(myKey.equals("title")){
message.setTitle(json.optString(myKey));
}else if(myKey.equals("date")){
message.setDate(json.optString(myKey));
}
}
} catch (JSONException e) {
Log.e(TAG, "Get message extra JSON error!");
}
}
}
return message;
}
示例2: onReceive
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
Log.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
//send the Registration Id to your server...
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 接收到推送下來的自定義消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 接收到推送下來的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.d(TAG, "[MyReceiver] 接收到推送下來的通知的ID: " + notifactionId);
processCustomMessage(context,bundle);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 用戶點擊打開了通知");
openNotification(context);
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
Log.d(TAG, "[MyReceiver] 用戶收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
//在這裏根據 JPushInterface.EXTRA_EXTRA 的內容處理代碼,比如打開新的Activity, 打開一個網頁等..
} else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
Log.d(TAG, "[MyReceiver]" + intent.getAction() +" connected state change to "+connected);
} else {
Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
}
} catch (Exception e){
}
}
示例3: onReceive
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Bundle bundle = intent.getExtras();
switch (action) {
case JPUSH_REGISTRATION:
LogUtil.e(JPUSH_REGISTRATION);
break;
case JPUSH_MESSAGE_RECEIVED:
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
LogUtil.e(JPUSH_MESSAGE_RECEIVED + "\t" + message);
break;
case JPUSH_NOTIFICATION_RECEIVED:
String content = bundle.getString(JPushInterface.EXTRA_ALERT);
LogUtil.e(JPUSH_NOTIFICATION_RECEIVED + "\t" + content);
break;
case JPUSH_NOTIFICATION_OPENED:
LogUtil.e(JPUSH_NOTIFICATION_OPENED);
break;
case JPUSH_NOTIFICATION_CLICK_ACTION:
LogUtil.e(JPUSH_NOTIFICATION_CLICK_ACTION);
break;
case JPUSH_CONNECTION:
LogUtil.e(JPUSH_CONNECTION);
break;
}
}
示例4: onReceive
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (TextUtils.equals(intent.getAction(), JPushInterface.ACTION_MESSAGE_RECEIVED)) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
if (!TextUtils.isEmpty(message)) {
try {
if (!JSONObject.NULL.equals(new JSONObject(message))) {
context.stopService(new Intent(context, LetvPushService.class));
Intent serviceIntent = new Intent(context, LetvPushService.class);
serviceIntent.putExtra(JPushInterface.EXTRA_MESSAGE, message);
context.startService(serviceIntent);
if (!TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_MSG_ID))) {
JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
示例5: onStartCommand
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
public int onStartCommand(Intent intent, int flags, int startId) {
LogInfo.log("push", "start query push");
if (intent == null || !(intent.getStringExtra(JPushInterface.EXTRA_MESSAGE) instanceof String)) {
this.mPushFrom = 0;
this.mDataIsFromNormal = true;
} else {
this.mPushFrom = 1;
this.mThirdPushData = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
}
new Thread(this) {
final /* synthetic */ LetvPushService this$0;
{
if (HotFix.PREVENT_VERIFY) {
System.out.println(VerifyLoad.class);
}
this.this$0 = this$0;
}
public void run() {
this.this$0.fetchData();
}
}.start();
return super.onStartCommand(intent, flags, startId);
}
示例6: onReceive
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
final Set<String> keys = bundle.keySet();
final JSONObject json = new JSONObject();
for (String key : keys) {
final Object val = bundle.get(key);
json.put(key, val);
}
LatteLogger.json("PushReceiver", json.toJSONString());
final String pushAction = intent.getAction();
if (pushAction.equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
//處理接收到的消息
onReceivedMessage(bundle);
} else if (pushAction.equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
//打開相應的Notification
onOpenNotification(context, bundle);
}
}
示例7: handleMessage
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
@Override
public void handleMessage(android.os.Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MSG_SET_ALIAS:
Log.d(TAG, "Set alias in handler.");
JPushInterface.setAliasAndTags(getApplicationContext(), (String) msg.obj, null, mAliasCallback);
break;
case MSG_SET_TAGS:
Log.d(TAG, "Set tags in handler.");
JPushInterface.setAliasAndTags(getApplicationContext(), null, (Set<String>) msg.obj, mTagsCallback);
break;
default:
Log.i(TAG, "Unhandled msg - " + msg.what);
}
}
示例8: onClick
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.init:
init();
break;
case R.id.setting:
Intent intent = new Intent(MainActivity.this, PushSetActivity.class);
startActivity(intent);
break;
case R.id.stopPush:
JPushInterface.stopPush(getApplicationContext());
break;
case R.id.resumePush:
JPushInterface.resumePush(getApplicationContext());
break;
case R.id.getRegistrationId:
String rid = JPushInterface.getRegistrationID(getApplicationContext());
if (!rid.isEmpty()) {
mRegId.setText("RegId:" + rid);
} else {
Toast.makeText(this, "Get registration fail, JPush init failed!", Toast.LENGTH_SHORT).show();
}
break;
}
}
示例9: processCustomMessage
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
private void processCustomMessage(Context context, Bundle bundle) {
if (MainActivity.isForeground) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
if (!ExampleUtil.isEmpty(extras)) {
try {
JSONObject extraJson = new JSONObject(extras);
if (extraJson.length() > 0) {
msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
}
} catch (JSONException e) {
}
}
context.sendBroadcast(msgIntent);
}
}
示例10: jumpToDetail
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
/**
* 跳轉頁麵 - 點擊通知後
*
* @param bundle 通知內容
*/
private void jumpToDetail(Context context, Bundle bundle) {
//清除指定通知
JPushInterface.clearNotificationById(context, bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID));
try {
JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
String id = json.getString("id");
String classid = json.getString("classid");
String type = json.getString("type");
LogUtils.d(TAG, "id = " + id + " classid = " + classid + " type = " + type);
if (type.equals("photo")) {
PhotoDetailActivity.start(context, classid, id);
} else {
NewsDetailActivity.start(context, classid, id);
}
} catch (JSONException e) {
LogUtils.d(TAG, "解析推送數據失敗");
}
}
示例11: startP2P
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
/**
* 跳轉至P2P界麵
*
* @param context
* @param bundle
* @throws JSONException
*/
private void startP2P(Context context, Bundle bundle) throws JSONException {
String alert = bundle.getString(JPushInterface.EXTRA_ALERT);
String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);
String notification = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
Logger.d(TAG, "[MyReceiver] notification - " + notification + ", extras: " + extra);
JSONObject jsonObject = new JSONObject(extra);
Bundle bundle1 = new Bundle();
bundle1.putString("userid", SharePrefUtil.getString("userid"));
bundle1.putString("callid", jsonObject.getString("p2p_userid"));
bundle1.putInt("p2p_mode", jsonObject.getInt("p2p_type"));
bundle1.putBoolean("p2p_push", true);
Intent i = new Intent(context, P2PCallActivity.class);
i.putExtras(bundle1);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
JPushInterface.clearNotificationById(context,bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID));
}
示例12: handlingNotificationOpen
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
private void handlingNotificationOpen(Context context, Intent intent) {
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
JPushUtil.openNotificationTitle = title;
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
JPushUtil.openNotificationAlert = alert;
Map<String, Object> extras = getNotificationExtras(intent);
JPushUtil.openNotificationExtras = extras;
JPushUtil.transmitNotificationOpen(title, alert, extras);
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launch);
}
示例13: handlingNotificationReceive
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
private void handlingNotificationReceive(Context context, Intent intent) {
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
JPushUtil.notificationTitle = title;
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
JPushUtil.notificationAlert = alert;
Map<String, Object> extras = getNotificationExtras(intent);
JPushUtil.notificationExtras = extras;
JPushUtil.transmitNotificationReceive(title, alert, extras);
}
示例14: initPlugin
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
public static void initPlugin(Context ctx) {
Log.i(TAG, "JPush initialize.");
cordovaCxt = ctx;
JPushInterface.init(cordovaCxt);
//如果同時緩存了打開事件 openNotificationAlert 和 消息事件 notificationAlert,隻向 UI 發打開事件。
//這樣做是為了和 iOS 統一。
if (openNotificationAlert != null) {
notificationAlert = null;
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
openNotificationExtras);
}
if (notificationAlert != null) {
transmitNotificationReceive(notificationTitle, notificationAlert,
notificationExtras);
}
}
示例15: onResume
import cn.jpush.android.api.JPushInterface; //導入依賴的package包/類
public void onResume(boolean multitasking) {
shouldCacheMsg = false;
Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert
+ "-" + notificationAlert);
if (isStatisticsOpened && multitasking) {
JPushInterface.onResume(NXTPushPlugin.getActivity());
}
if (openNotificationAlert != null) {
notificationAlert = null;
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
openNotificationExtras);
}
if (notificationAlert != null) {
transmitNotificationReceive(notificationTitle, notificationAlert,
notificationExtras);
}
}