Bootstrap

Android 极光推送快速开发集成指南(1)

<activity

android:name=“cn.jpush.android.ui.PushActivity”

android:configChanges=“orientation|keyboardHidden”

android:exported=“false”

android:theme=“@android:style/Theme.NoTitleBar”

tools:ignore=“DuplicateActivity”>

<activity

android:name=“cn.jpush.android.ui.PopWinActivity”

android:configChanges=“orientation|keyboardHidden”

android:exported=“false”

android:theme=“@style/MyDialogStyle”>

<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());

}

}

;