[置顶] Android开发坑之Jpush篇

Android开发会用到各种各样的推送,自己写、信鸽、Jpush、百度、个推等等,形形色色。

今天我们来扒扒Jpush的一些坑:

1.statusBar图标显示不全:

这个坑在部分机器上会出现,华为、Samsung等。

遇到这个问题,相信一开始有些人就各种修改app的图标,然后各种不行。

其实Jpush的推送图标以及statusBar图标都可以修改,最好的方式是自定义推送样式。

CustomPushNotificationBuilder builder = new
        CustomPushNotificationBuilder(this,
        R.layout.customer_notitfication_layout,
        R.id.icon,
        R.id.title,
        R.id.text);
// 指定定制的 Notification Layout
builder.statusBarDrawable = R.drawable.app_icon_notify;
// 指定最顶层状态栏小图标
builder.layoutIconDrawable = R.drawable.app_icon;
// 指定下拉状态栏时显示的通知图标
JPushInterface.setPushNotificationBuilder(1, builder);

细心查看文档的话就可以找到这个api。

附上Android各种图标的尺寸:

[置顶] Android开发坑之Jpush篇_第1张图片


2.设定了自定义推送样式,但是推送过来了还是显示以前的样式:

通过该方法设定自定义样式

JPushInterface.setPushNotificationBuilder(1, builder);

Jpush该接口提供设置多套自定义样式,通过参数一来设定。

不过要用上这套样式,需要推送添加通知栏样式编号,默认为0。

既然默认为0,那我把参数一改为0不就可以了么?小编就曾遇到这样的情况,使用setPushNotificationBuilder设定编号为0,但是推送过来仍然不生效。

细心查看文档,会发现Jpush提供另一个接口设定默认样式:

JPushInterface.setDefaultPushNotificationBuilder(builder);
该问题解决了。

附上能够适应各款手机的自定义通知栏样式布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:internal="http://schemas.android.com/apk/prv/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    internal:layout_maxHeight="64dp"
    internal:layout_minHeight="64dp">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:scaleType="center" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_vertical"
        android:layout_marginLeft="64dp"
        android:layout_marginStart="64dp"
        android:gravity="center_vertical"
        android:minHeight="64dp"
        android:orientation="vertical"
        android:paddingBottom="2dp"
        android:paddingEnd="8dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingStart="8dp"
        android:paddingTop="2dp">

        <TextView
            android:id="@+id/title"
            style="@style/android:TextAppearance.StatusBar.EventContent.Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true" />

        <TextView
            android:id="@+id/text"
            style="@style/android:TextAppearance.StatusBar.EventContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/title" />

    </LinearLayout>

</FrameLayout>


3.通过Alias进行推送:卸载App后发生了一次推送,这时重新安装并启动App会收到该条推送:

该问题和Jpush的架构有关系,Jpush客服也说明有该问题,但是暂时无法解决。


如果广大网友有遇到其他坑,欢迎留言一起探讨!


如有转载,请注明出处:http://blog.csdn.net/hjhrq1991



你可能感兴趣的:(android,推送,Jpush)