Android notification设置的图标不显示

跟着谷歌的android fundamental tutorial作安卓通知部分时,在魅族flyme系统上并不显示我设置的通知icon,而是显示默认的应用启动图标。而且奇怪的是我设置的通知是等级最高的,系统给我折叠到了不重要的消息里面也没有声音提示,求教。
target API:26.0
使用的icon是AS自带的透明图标
我参照的教程地址

public class MainActivity extends AppCompatActivity {

    private ToggleButton mToggleButton;
    private NotificationManager notificationManager;
    private static final int NOTIFICATION_ID=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mToggleButton= findViewById(R.id.alarmToggle);
        //改变togglebutton文字
//        mToggleButton.setTextOff("Off");
//        mToggleButton.setTextOn("On");
//        mToggleButton.setText("Off");
        mToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                String toastMessage;
                if (b){
                    toastMessage=getString(R.string.toggleButton_on);
                    deliverNotification(MainActivity.this);
                }
                else {
                    toastMessage=getString(R.string.toggleButton_off);
                    notificationManager.cancelAll();
                }
                Toast.makeText(MainActivity.this,toastMessage,Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void deliverNotification(Context context){

        Intent notificationIntent = new Intent(context,MainActivity.class);
        PendingIntent notificationPendingIntent =PendingIntent.getActivity(
                context,NOTIFICATION_ID,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

//        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"StandUp")
                .setSmallIcon(R.drawable.ic_run)
                //这里设定的图标是AS里随便找的一个,设置了没效果
                .setContentTitle(getString(R.string.notification_title))
                .setContentText(getString(R.string.notification_text))
                .setContentIntent(notificationPendingIntent)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setAutoCancel(true);

//        notificationManager.notify(NOTIFICATION_ID,builder.build());
        notificationManager.notify(NOTIFICATION_ID,builder.build());
    }
}

image

阅读 5.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题