极光推送官方配置地址:点我

配置以下基本功能,如果还未能接受到推送,可前往极光社区寻求答案
极光推送3分集成干货--Android_第1张图片

app.build.gradle文件中:

android {        ...        defaultConfig {            ...            // ---------------- 极光推送配置 Start ---------------------------            ndk {                //选择要添加的对应cpu类型的.so库。                abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'                // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'            }            manifestPlaceholders = [                    JPUSH_PKGNAME: applicationId,                    JPUSH_APPKEY : "您的key", //JPush上注册的包名对应的appkey.                    JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可.            ]            // ---------------- 极光推送配置 End ---------------------------            }        ...        }dependencies {    ...    // 极光推送配置 201832113:54:08    compile 'cn.jiguang.sdk:jpush:3.1.1'    compile 'cn.jiguang.sdk:jcore:1.1.9'}

manifest文件:

                <receiver            android:name="你自定义的Receiver"            android:enabled="true">            <intent-filter>                                <action android:name="cn.jpush.android.intent.REGISTRATION" />                                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />                                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />                                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />                                <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />                                <action android:name="cn.jpush.android.intent.CONNECTION" />                <category android:name="您的包名" />            intent-filter>        receiver>        

需要自定义一个Receiver

public class JPushReceiver extends BroadcastReceiver {    private static final String TAG = "JPushReceiver";    @Override    public void onReceive(Context context, Intent intent) {        Bundle bundle = intent.getExtras();        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {            Log.i(TAG, "用户注册成功,注册ID : " + bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID));        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {            Log.i(TAG, "接收到自定义消息");        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {            Log.i(TAG, "接收到通知,通知ID:" + bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID));        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {            Log.i(TAG, "用户点击了通知");//            Intent i = new Intent(context, MainActivity.class);//            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);        } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {            Log.i(TAG, "接收到富媒体消息");        } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {            Log.i(TAG, "与极光服务器的长连接发送了变化" + intent.getAction() + " connected state change to " + intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false));        } else {            Log.i(TAG, "未知的意图 - " + intent.getAction());        }    }}

每一个手机唯一的极光ID(传给后台):

JPushInterface.getRegistrationID(this)

最后在Application中初始化即可:

/** 极光初始化 */JPushInterface.setDebugMode(true);  // 设置开启日志,发布时请关闭日志JPushInterface.init(this);          // 初始化 JPush

好了,到这里您就完成了最简易的极光推送集成,如果需要更多推送功能您可以去官网API查看,如果有任何关于极光推送的问题均可去极光社区提问,也许社区首页就有项目中bug的解决方法。

更多相关文章

  1. Android用户界面UI组件--AdapterView及其子类(三) ExpandableLis
  2. Android应用程序未捕获异常并提示用户发送给开发者
  3. Android之用户定位(三)
  4. Android Notification通知栏、点击事件、悬浮通知的简单实现
  5. 【demo记录】极光推送(android app访问服务器,服务器推送信息到新a
  6. android通知栏Notification
  7. android通过webservice验证用户
  8. android通过USB的MTP模式下,禁止用户在根目录有任何操作(重命名 删

随机推荐

  1. 解决windows service 2012阿里云服务器在
  2. 使用Visual Studio Code连接MySql数据库
  3. mysql添加备注信息的实现
  4. 深入理解r2dbc在mysql中的使用
  5. 浅谈Mysql哪些字段适合建立索引
  6. nacos无法连接mysql的解决方法
  7. mysql5.7 设置远程访问的实现
  8. MySQL查询优化之查询慢原因和解决技巧
  9. 详解mysql 使用left join添加where条件的
  10. 浅谈为什么Mysql数据库尽量避免NULL