最后的最后
对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的
最后,互联网不存在所谓的寒冬,只是你没有努力罢了!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
通知就是可以再通知栏显示提醒用户的信息,而消息不会在通知栏显示,业务逻辑可以完全有开发者来定。
3、推送对象
可以分为:
广播:会把通知无区别的推送到每个人身上。
设置标签:这一般用于群组推送。
设置别名:适用于单播,根据客户端设置的别名来推送。
设置注册ID:适用于单播推送,指定推送给某一个人,可以使注册过的用户ID,主要用来区分。
4、自定义通知栏样式、附加字段的作用
我们有时候可能不想直接用Android原生的通知栏样式,如果服务提供相应的API的话,我们可以通过自定义布局来达到这个目的。极光这里提供了以下方法:
// 自定义Notification样式
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
getApplicationContext(),
R.layout.customer_notitfication_layout, R.id.icon, R.id.title,
R.id.text);
builder.layoutIconDrawable = R.drawable.ic_launcher;
builder.developerArg0 = “developerArg2”;
JPushInterface.setPushNotificationBuilder(2, builder);
Toast.makeText(getApplicationContext(), “Custom Builder - 2”,
Toast.LENGTH_SHORT).show();
我们只需要指定通知栏编号,下次推送通知的时候就会以自定义的通知栏样式来显示。
这里还有一个附加字段,我们有时候可能需要根据推送的不同消息来实现跳转不同的页面,这时候就可能需要用到附加字段了,我们在Broadcast Receiver来接受推送下来的消息,解析附加字段内容,来达到我们的目的。
代码示例:
package com.infzm.daily.know.receiver;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import cn.jpush.android.api.JPushInterface;
import com.infzm.daily.know.ArticleDetailActivity;
import com.infzm.daily.know.MainActivity;
import com.infzm.daily.know.utils.LogUtils;
public class PushReceiver extends BroadcastReceiver {
private static final String TAG = “JPush”;
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
LogUtils.logi(TAG, "[PushReceiver] onReceive - " + intent.getAction() + ", extras: "+ printBundle(bundle));
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
LogUtils.logi(TAG, "[PushReceiver] 接收Registeration Id : " + regId);
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
LogUtils.logi(TAG, "[PushReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
}else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
LogUtils.logi(TAG, “[PushReceiver] 接收到推送下来的通知”);
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
LogUtils.logi(TAG, "[PushReceiver] 接收到推送下来的通知的ID: " + notifactionId);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
LogUtils.logi(TAG, “[PushReceiver] 用户点击打开了通知”);
String type = bundle.getString(JPushInterface.EXTRA_EXTRA);
LogUtils.loge(TAG, “type:” + type);
try {
JSONObject jsonObject = new JSONObject(type);
String str = jsonObject.getString(“key”);
if (str.equals(“1”)) {
//打开自定义的Activity
Intent i = new Intent(context, MainActivity.class);
bundle.putInt(“index”, 1);
i.putExtras(bundle);
//i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
context.startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
LogUtils.logi(TAG, "[PushReceiver] 用户收到到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);
LogUtils.logi(TAG, “[PushReceiver]” + intent.getAction() +" connected state change to "+connected);
} else {
LogUtils.logi(TAG, "[PushReceiver] Unhandled intent - " + intent.getAction());
}
}
// 打印所有的 intent extra 数据
private static String printBundle(Bundle bundle) {
StringBuilder sb = new StringBuilder();
for (String key : bundle.keySet()) {
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
sb.append(“\nkey:” + key + “, value:” + bundle.getInt(key));
}else if(key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)){
sb.append(“\nkey:” + key + “, value:” + bundle.getBoolean(key));
}
else {
sb.append(“\nkey:” + key + “, value:” + bundle.getString(key));
}
学习交流
群内有许多来自一线的技术大牛,也有在小厂或外包公司奋斗的码农,我们致力打造一个平等,高质量的Android交流圈子,不一定能短期就让每个人的技术突飞猛进,但从长远来说,眼光,格局,长远发展的方向才是最重要的。
35岁中年危机大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
大多是因为被短期的利益牵着走,过早压榨掉了价值,如果能一开始就树立一个正确的长远的职业规划。35岁后的你只会比周围的人更值钱。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!