Android-自定义Notification,一起刷完了这份1307页的Android面试宝典吧

本文介绍了如何在Android中实现自定义Notification,包括旧方法和新方法的使用,并探讨了面试准备的重要性。作者强调要全面掌握基础知识,提供了一份面试题资料链接,以帮助开发者在面试中脱颖而出。
摘要由CSDN通过智能技术生成

package com.wwj.custom.notification;

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Context;

import android.content.Intent;

import android.graphics.BitmapFactory;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

/**

  • 自定义Notification

  • @author wwj

*/

public class MainActivity extends Activity implements OnClickListener {

private Button showNotification;

private Button showCustomNotifi;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

showNotification = (Button) findViewById(R.id.button1);

showCustomNotifi = (Button) findViewById(R.id.button2);

showNotification.setOnClickListener(this);

showCustomNotifi.setOnClickListener(this);

}

@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.button1:

send();

break;

case R.id.button2:

custom();

break;

default:

break;

}

}

/**

  • 旧方法

*/

public void send() {

// 1 得到通知管理器

NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// 2构建通知

Notification notification = new Notification(

android.R.drawable.stat_notify_chat, “这是提示信息”,

System.currentTimeMillis());

// 3设置通知的点击事件

Intent intent = new Intent(this, MainActivity.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 100,

intent, 0);

notification.setLatestEventInfo(this, “通知的标题”, “通知的内容”, contentIntent);

notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知之后自动消失

// 4发送通知

nm.notify(100, notification);

}

/**

  • 自定义Notification 新方法

  • 新的方法,本人在手机测试会崩溃,如果不行的话,可以继续使用旧的构建方法,毕竟高版本会兼容低版本的

题外话

不管怎么样,不论是什么样的大小面试,要想不被面试官虐的不要不要的,只有刷爆面试题题做好全面的准备,当然除了这个还需要在平时把自己的基础打扎实,这样不论面试官怎么样一个知识点里往死里凿,你也能应付如流啊~

这里我为大家准备了一些我工作以来以及参与过的大大小小的面试收集总结出来的一套进阶学习的视频及面试专题资料包,点击这里免费分享给大家,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家~

最后如果马化腾把腾讯给你一天,你会来做什么?欢迎评论区讨论。

95%E6%8B%BF%E9%AB%98%E8%96%AA%EF%BC%81.md)给大家,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家~

[外链图片转存中…(img-eB62O5P4-1643948035804)]

最后如果马化腾把腾讯给你一天,你会来做什么?欢迎评论区讨论。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值