android电量显示图标不显示,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());

}

}

bV73qi?w=1080&h=1920

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值