极光推送 (具体步骤,指导操作,推送成功)

2018-07-29  本文已影响0人  测天测地测空气

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

image.png

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

image.png

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

image.png

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

image.png

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

image.png

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

image.png image.png image.png

【七、点击下载Demo】

image.png

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

image.png image.png

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

image.png

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

image.png image.png

    <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>

image.png image.png image.png

【十一、Sync Now 等运行完毕就OK咯】

【十二、开始推送(以上为自动集成步骤)】

image.png image.png

 <receiver
            android:name=".di.global.PushReceiver"
            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.png image.png image.png image.png image.png image.png
![image.png](https://img.haomeiwen.com/i10678090/bb377e5a0084a099.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
image.png image.png image.png image.png image.png image.png
public static boolean isForeground = false;

    @Override
    protected void onResume() {
        isForeground = true;
        super.onResume();
    }

    @Override
    protected void onPause() {
        isForeground = false;
        super.onPause();
    }

image.png

    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){
            }
        }
    }

 setCostomMsg(showMsg.toString());//删除

Toast.makeText(context, showMsg.toString(), Toast.LENGTH_SHORT).show();

image.png image.png image.png image.png image.png image.png
*推送对象选择android,点击立即发送
image.png

*立即发送

image.png

*推送成功

image.png image.png

还有定时推送,大家可以慢慢探索,@希望能帮到大家!谢谢

上一篇下一篇

猜你喜欢

热点阅读