<service
android:name=“.service.JpushBackgroudeService”
android:enabled=“true”
android:exported=“false”
android:process=“:pushcore”>
<receiver
android:name=“.receiver.PushBackgroudeBrocast”
android:enabled=“true”
android:exported=“false”>
<receiver
android:name=“包名”
android:enabled=“true”
android:exported=“false”>
<activity
android:name=“cn.jpush.android.service.JNotifyActivity”
android:exported=“true”
android:taskAffinity=“jpush.custom”
android:theme=“@android:style/Theme.Translucent.NoTitleBar”>
在gradle中的
defaultConfig{
ndk {
abiFilters ‘armeabi-v7a’, ‘x86’, ‘x86_64’, ‘armeabi-v7a’//,‘arm64-v8a’
}
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : “你的ID”, //JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL: “developer-default”, //暂时填写默认值即可.
]
}
这样 配置就算可以了,然后在包下,复制从官网下载的demo,到包里,参考地址:https://docs.jiguang.cn//jpush/client/Android/android_3m/
比如TagAliasOperatorHelper这个工具类 改好以后在全局的Applition中 初始化
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
String registrationID = JPushInterface.getRegistrationID(this);//这个可以传给后台 推送到具体的个人
如上配置好之后:
检查一下有没有通知栏权限
package xxx;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class CheckAndStartNitifycationUtils
{
public static boolean isNotificationEnabled(Context context) {
String CHECK_OP_NO_THROW = “checkOpNoThrow”;
String OP_POST_NOTIFICATION = “OP_POST_NOTIFICATION”;
AppOpsManager mAppOps = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
}
ApplicationInfo appInfo = context.getApplicationInfo();
String pkg = context.getApplicationContext().getPackageName();
int uid = appInfo.uid;
Class appOpsClass = null;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
appOpsClass = Class.forName(AppOpsManager.class.getName());
}
Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
String.class);
Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
int value = (Integer) opPostNotificationValue.get(Integer.class);
return ((Integer) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static void startNotifyCationAction(Context context)
{
// boolean enabled = isNotificationEnabled(context);
// if (!enabled) {
/**
-
跳到通知栏设置界面
-
@param context
*/
Intent localIntent = new Intent();
//直接跳转到应用通知设置的代码:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
localIntent.setAction(“android.settings.APP_NOTIFICATION_SETTINGS”);
localIntent.putExtra(“app_package”, context.getPackageName());
localIntent.putExtra(“app_uid”, context.getApplicationInfo().uid);
} else if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
localIntent.addCategory(Intent.CATEGORY_DEFAULT);
localIntent.setData(Uri.parse(“package:” + context.getPackageName()));
} else {
//4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction(“android.settings.APPLICATION_DETAILS_SETTINGS”);
localIntent.setData(Uri.fromParts(“package”, context.getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName(“com.android.settings”, “com.android.setting.InstalledAppDetails”);
localIntent.putExtra(“com.android.settings.ApplicationPkgName”, context.getPackageName());
}
尾声
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。 整理的这些架构技术希望对Android开发的朋友们有所参考以及少走弯路,本文的重点是你有没有收获与成长,其余的都不重要,希望读者们能谨记这一点。
最后想要拿高薪实现技术提升薪水得到质的飞跃。最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以为了大家能够顺利进阶中高级、架构师,我特地为大家准备了一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。
进阶学习视频
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
14688074609)]
当你有了学习线路,学习哪些内容,也知道以后的路怎么走了,理论看多了总要实践的。
进阶学习视频
[外链图片转存中…(img-z82phsbl-1714688074609)]
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题 (含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-gTauaobw-1714688074610)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!