https://note.youdao.com/ynoteshare1/index.html?id=7fd642cbe1e4c3b1746e275869cfd0b5&type=note
第一步:导入依赖
implementation 'cn.jiguang.sdk:jpush:3.3.0' // 此处以JPush 3.3.0 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.0.1' // 此处以JCore 2.0.1 版本为例。
//defaultConfig下导入
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "ce5eac1c2a6fdb0a27660f72", //自己应用的AppKey Appkey.
JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.
]
packagingOptions{
doNotStrip '*/mips/*.so'
doNotStrip '*/mips64/*.so'
}
//以上完毕 build一下
/***************************************/
第二步:添加权限 清单文件
<!-- Required -->
<uses-permission android:name="bawei.com.jiguangtuishong.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional. Required for location feature -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 用于开启 debug 版本的应用在 6.0 系统上的层叠窗口权限 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
//--------------------------------------------------------------
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".push.ExampleApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//复制红色字***********复制到application
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER" />
<action android:name="cn.jpush.android.intent.REPORT" />
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service>
<provider
android:authorities="bawei.com.jiguangtuishong.DownloadProvider"//改包名
android:name="cn.jpush.android.service.DownloadProvider"
android:exported="true"
/>
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true" >
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<category android:name="bawei.com.jiguangtuishong"/>//改包名
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<receiver android:name="cn.jpush.android.service.AlarmReceiver" />
<receiver
android:name="bawei.com.jiguangtuishong.push.MyJPushMessageReceiver"//改包名
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="bwie.com.tuisong" />
</intent-filter>
</receiver>
<service android:name="bawei.com.jiguangtuishong.push.MyService"//改包名
android:enabled="true"
android:exported="false"
android:process=":pushcore">
<intent-filter>
<action android:name="cn.jiguang.user.service.action" />
</intent-filter>
</service>
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<!-- Required. AppKey copied from Portal -->
<meta-data android:name="JPUSH_APPKEY" android:value="ce5eac1c2a6fdb0a27660f72"/>//自己应用的AppKey
</application>
/***************************************/
//第三步 下载里边的Demo复制一下一下俩个类
//把里边MyJPushMessageReceiver报红的删除
package com.bawei.day0528jiguang;
import android.content.Context;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.service.JPushMessageReceiver;
/**
* 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
* */
public class MyJPushMessageReceiver extends JPushMessageReceiver {
@Override
public void onTagOperatorResult(Context context,JPushMessage jPushMessage) {
super.onTagOperatorResult(context, jPushMessage);
}
@Override
public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){
super.onCheckTagOperatorResult(context, jPushMessage);
}
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
}
@Override
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
super.onMobileNumberOperatorResult(context, jPushMessage);
}
}
//把ExampleApplication里边的 Logger 实现一下
package com.bawei.day0528jiguang;
import android.app.Application;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.helper.Logger;
/**
* For developer startup JPush SDK
*
* 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
*/
public class ExampleApplication extends Application {
private static final String TAG = "JIGUANG-Example";
@Override
public void onCreate() {
Logger.d(TAG, "[ExampleApplication] onCreate");
super.onCreate();
JPushInterface.setDebugMode(true); // 设置开启日志,发布时请关闭日志
JPushInterface.init(this); // 初始化 JPush
}
}
//自己在创建一个MyService 继承 JCommonService 如下
package com.bawei.day0528jiguang;
import cn.jpush.android.service.JCommonService;
/**
* @Author:
* @E-mail: 2212096722@qq.com
* @Date: 2019/5/17 20:18
* @Description:描述信息
*/
public class MyService extends JCommonService {
}
//最后去清单文件把这些类实现一下
到推送平台推送一下 点击推送 发送通知
输入内容 选择安卓 立即发送