Android 悬挂式通知是Android 在5.0以后才有的。在5.0以前通过设置setTicker 来实现
。在5.0 以上、8.0以上通过设置setFullScreenIntent。在8.0以上需要设置
NotificationChannel 的优先级为NotificationManager.IMPORTANCE_HIGH
即可。但是在使用过程中可能会出现很多特殊情况。
比如:悬挂通知栏无法弹窗、会直接进入目标Activity、或者其他情况。
下边是适配过的悬挂式通知栏实例代码:
//获取PendingIntent
android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent();
PendingIntent mainPendingIntent = PendingIntent.getBroadcast(context, Integer.valueOf(alramId), intent, FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(Application.getInstance().getPackageName(),R.layout.notify_drop);
NotificationCompat.Builder builder = new NotificationCompat.Builder(TimeApplication.getInstance());
builder.setLargeIcon(BitmapFactory.decodeResource(TimeApplication.getInstance().getResources(),R.mipmap.ic_launcher))
.setSmallIcon(R.mipmap.ic_launcher)//不能缺少的一个属性
.setContentIntent(mainPendingIntent)
.setCustomContentView(views)
.setAutoCancel(true)
.setLights(0, 0, 0)
.setWhen(System.currentTimeMillis());//设置通知时间
builder.setDefaults(Notification.DEFAULT_ALL);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel;
if(eventDataEntity.soundposition == 0){
channel = new NotificationChannel(String.valueOf(CHANNEL_ID), "提醒通知", NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
channel.getAudioAttributes();
notificationManager.createNotificationChannel(channel);
builder.setChannelId(String.valueOf(CHANNEL_ID));
builder.setCustomContentView(views);
}else{
channel = new NotificationChannel(String.valueOf(CHANNEL_CUSTOM_ID), "自定义铃声提醒通知", NotificationManager.IMPORTANCE_HIGH );
channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
channel.getAudioAttributes();
channel.setSound(null,null);
notificationManager.createNotificationChannel(channel);
builder.setChannelId(String.valueOf(CHANNEL_CUSTOM_ID));
builder.setCustomContentView(views);
}
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
if(isNeedSetFullScreen()){
CustomLog.e("提醒事件 === 2");
builder.setFullScreenIntent(mainPendingIntent,true);
}
// builder.setVisibility(Notification.VISIBILITY_PUBLIC);
// builder.setTicker("悬浮通知");
// builder.setDefaults(Notification.DEFAULT_ALL);
// builder.setPriority(Notification.PRIORITY_MAX);
}
notificationManager.notify(Integer.parseInt(alramId), builder.build());
/**
* 是否需要设置setFullScreenIntent
* @return
*/
public static boolean isNeedSetFullScreen(){
CustomLog.e("当前手机品牌 =" + Build.MANUFACTURER);
boolean isNeed;
switch (Build.MANUFACTURER) {
case MANUFACTURER_HUAWEI://华为
case MANUFACTURER_Huawei:
isNeed = false;
break;
case MANUFACTURER_MEIZU://魅族
isNeed = false;
break;
case MANUFACTURER_XIAOMI://小米
isNeed = false;
break;
case MANUFACTURER_SONY://索尼
isNeed = false;
break;
case MANUFACTURER_OPPO://oppo
isNeed = false;
break;
case MANUFACTURER_LG://lg
isNeed = false;
break;
case MANUFACTURER_LETV://乐视
isNeed = false;
break;
case MANUFACTURER_VIVO:
isNeed = true;
break;
case MANUFACTURER_SAMSUNG:
isNeed = false;
break;
case MANUFACTURER_ZTE:
isNeed = false;
break;
case MANUFACTURER_YULONG:
isNeed = false;
break;
case MANUFACTURER_LENOVO:
isNeed = false;
break;
default:
isNeed =true;
break;
}
return isNeed;
}
在使用裁剪的时候必须添加以下代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
//添加这一句表示对目标应用临时授权该Uri所代表的文件
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//通过FileProvider创建一个content类型的Uri
// uri = FileProvider.getUriForFile(this, "包名.fileProvider", file);
}
修改litpal默认主键id 的初始化值,需要覆写
@Override
public void assignBaseObjId(int baseObjId) {
//修改初始值为 1 ,修改时一定要注意这样使用会不会对你现有的逻辑发生影响。
super.assignBaseObjId(1);
}
目前支持的html标签很基础,p 、h 、font 等等。
span标签在6.0以上的手机系统已经开始支持,6.0以下不起作用。如果是字体颜色等的调整可以使用font。
原因:因为Glide 库底层对bitmap 有复用的处理。而且是指向同一块内存地址。所有在加载其他bimap图片的时候。只是改变了内容,地址没有变化。这个时候其他ImageView或者控件在使用的时候,就会变成该地址所对应的最新的bitmap 图片。
修改:
使用时只要重新创建Bitmap 对象。而不是直接使用Glide 返回的bitmap。
git init
git remote add trans_old https://××××××××××.git (旧的git仓库代码地址)
git remote add trans_new https://×××××××××.git (新的git仓库代码地址)
git fetch trans_old
git fetch trans_new
git checkout -b trans_new/branchName
git merge trans_old/branchName
git push trans_new trans_new/branchName
SDK版本名 | API Level |
---|---|
Android 9.0 (Pie) | 28 |
Android 8.1 (Oreo) | 27 |
Android 8.0 (Oreo) | 26 |
Android 7.1.1 (Nougat) | 25 |
Android 7.0 (Nougat) | 24 |
Android 6.0 (Marshmallow) | 23 |
Android 5.1 (Lollipop) | 22 |
Android 5.0 (Lollipop) | 21 |
Android 4.4W (KitKat Wear) | 20 |
Android 4.4 (KitKat) | 19 |
Android 4.3 (Jelly Bean) | 18 |
Android 4.2 (Jelly Bean) | 17 |
Android 4.1 (Jelly Bean) | 16 |
Android 4.0.3 (IceCreamSandwich) | 15 |
Android 4.0 (IceCreamSandwich) | 14 |
Android 3.2 (Honeycomb) | 13 |
Android 3.1 (Honeycomb) | 12 |
Android 3.0 (Honeycomb) | 11 |
Android 2.3.3 (Gingerbread) | 10 |
Android 2.3 (Gingerbread) | 9 |
Android 2.2 (Froyo) | 8 |
Android 2.1 (Eclair) | 7 |
Android 2.0.1 (Eclair) | 6 |
Android 2.0 (Eclair) | 5 |
Android 1.6 (Dout) | 4 |
Android 1.5 (Cupcake) | 3 |
Android 1.1 (Base) | 2 |
Android 1.0 (Base) | 1 |
解决版本,修改build.gradle文件。
替换为
buildscript {
repositories {
jcenter{
url 'https://jcenter.bintray.com/'
}
maven {
url 'https://maven.google.com'
// url 'http://maven.aliyun.com/nexus/content/repositories/releases/' //阿里云仓库地址
}
// maven {
// url 'http://maven.aliyun.com/nexus/content/repositories/releases/' //阿里云仓库地址
// }
// maven {
// url 'http://maven.aliyun.com/nexus/content/repositories/releases/' //阿里云仓库地址
// }
google()
maven {
url "http://10.241.11.54:18080/nexus/repository/maven-open-releases/"
}
maven {
url "http://10.241.11.54:18080/nexus/repository/maven-open-snapshots/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
maven {
url 'https://maven.google.com'
// url 'http://maven.aliyun.com/nexus/content/repositories/releases/' //阿里云仓库地址
// }
maven {
url 'https://maven.google.com'
// url 'http://maven.aliyun.com/nexus/content/repositories/releases/' //阿里云仓库地址
}
jcenter {
url 'https://jcenter.bintray.com/'
}
maven { url 'http://developer.huawei.com/repo/' }
maven { url 'https://jitpack.io' }
google()
maven {
url "http://10.241.11.54:18080/nexus/repository/maven-open-releases/"
}
maven {
url "http://10.241.11.54:18080/nexus/repository/maven-open-snapshots/"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
- git log -g 查找提交的commit,并记录commit_id
- git branch “branch” commit_id
- 切换到“branch”分支,检查文件是否存在,即可。