[一、百度一下:极光推送的官网]

[二、进入官网,并注册账号登录]

[三、点击“应用管理”,并“创建应用”]

[四、应用名称、应用图标随意起名,上传,最后点击“创建我的应用”]

[五、请记好你的AppKey,然后点击“完成推送设置”]

[六、我们先测试android,请填入你”项目的包名”,最后点击保存,弹出一个窗口,我们点击确定]

-
在项目的build.gradle的Module:app中获取包名
image

【七、点击下载Demo】

【八、下载完成后,建一个文件夹,把压缩包放进去然后解压到当前文件夹】


【九、返回浏览器,点击查看集成指南】

【十、我们选择自动集成】

-
在项目的清单文件中,把service这段复制到application中去,tools报红就导包,name爆红先不管
image
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
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>
//把service这段复制,tools报红就导包,name爆红先不管
<service android:name="cn.jpush.android.service.PushService"
android:process=":multiprocess"
tools:node="replace" >
</service>
</application>
- 确认android studio的 Project 根目录的主 gradle 中配置了jcenter支持。(新建project默认配置就支持)

-
在 module 的 gradle 中添加依赖和AndroidManifest的替换变量。
image
-
注意修改AppKey,并Sync Now
image
【十一、Sync Now 等运行完毕就OK咯】
【十二、开始推送(以上为自动集成步骤)】
-
在清单文件AndroidManifest中,复制Required这段请求
image
-
在清单文件中复制receiver这段
image
<receiver
android:name=".di.global.PushReceiver" //换成自己的receiver路径!!!
android:enabled="true"
android:exported="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.NOTIFICATION_CLICK_ACTION" />
<action android:name="cn.jpush.android.intent.CONNECTION" />
<category android:name="com.example.myproject" />
</intent-filter>
</receiver>
-
在工程中加混淆
image
image
-
在项目中创建App继承Application,不要忘记在清单文件的Application中添加name!!!
image
image
-
新建一个Receiver
image
image
-
打开我们刚下的Demo,打开MyReceiver.java,把里面的内容都复制到项目的PushReceiver中去
image
image
-
爆红了是吧,我们接着在下载的Demo中复制Logger.java到项目中去,直接复制啊!!!
image
-
还爆红对不对,注意项目导的包,我们删除这个就好啦
image
-
接下来创建一个Activity,是为了自定义推送的内容
image
image
-
在Activity的布局中加一个TextView布局
image
-
还有报红的没解决,接着来
image
-
打开下载的Demo中的MainActivity,查找有关isForeground的所有代码,并复制到项目中的MainActivity中去
public static boolean isForeground = false;
@Override
protected void onResume() {
isForeground = true;
super.onResume();
}
@Override
protected void onPause() {
isForeground = false;
super.onPause();
}
-
打开下载的Demo中的MainActivity,查找有关isForeground的所有代码,并复制到项目中的MainActivity中去
image
private MessageReceiver mMessageReceiver;
public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
public static final String KEY_TITLE = "title";
public static final String KEY_MESSAGE = "message";
public static final String KEY_EXTRAS = "extras";
public void registerMessageReceiver() {
mMessageReceiver = new MessageReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(MESSAGE_RECEIVED_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter);
}
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {
String messge = intent.getStringExtra(KEY_MESSAGE);
String extras = intent.getStringExtra(KEY_EXTRAS);
StringBuilder showMsg = new StringBuilder();
showMsg.append(KEY_MESSAGE + " : " + messge + "\n");
if (!ExampleUtil.isEmpty(extras)) {
showMsg.append(KEY_EXTRAS + " : " + extras + "\n");
}
setCostomMsg(showMsg.toString());
}
} catch (Exception e){
}
}
}
- 把这行删去,改为Toast
setCostomMsg(showMsg.toString());//删除
Toast.makeText(context, showMsg.toString(), Toast.LENGTH_SHORT).show();
-
剩下最后一个爆红的了,打开下载的Demo并把ExampleUtil.java复制到项目中去
image
image
-
返回浏览器,点击统计,发现我们的累积用户为0
image
-
运行我们的项目到手机上去(模拟器也可以)
image
-
刷新刚刚的浏览器,发现用户变成1了,表示集成成功,可以推送了
image
-
点击浏览器的”推送---发送通知”,在输入框填写你想要推送的内容
image
-
推送对象选择android,点击立即发送
image
-
立即发送
image
-
推送成功
image
image
网友评论