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());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论