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

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

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

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;

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)]

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5722009.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存