博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
8.0的适配
阅读量:7222 次
发布时间:2019-06-29

本文共 3833 字,大约阅读时间需要 12 分钟。

hot3.png

8.0的图标适配:Ctrl Shift A 弹出框  输入image Assert

分为前景图和背景图(可以是背景颜色或者是png、jpg的图片)

8.0的通知栏适配:

package huike.qu.com.testicon;import android.annotation.TargetApi;import android.app.Notification;import android.app.NotificationChannel;import android.app.NotificationManager;import android.content.Intent;import android.graphics.BitmapFactory;import android.os.Build;import android.provider.Settings;import android.support.v4.app.NotificationCompat;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Toast;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        // 创建渠道        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){            String chatChannelId = "chat";            String chatChannelName = "聊天";            int chatImportance = NotificationManager.IMPORTANCE_HIGH;            createNoticficationChannel(chatChannelId,chatChannelName,chatImportance);            String SubscribChannelId = "subscribe";            String SubscribChannelName = "订阅";            int SubscribImportance = NotificationManager.IMPORTANCE_DEFAULT;            createNoticficationChannel(SubscribChannelId,SubscribChannelName,SubscribImportance);        }    }    @TargetApi(Build.VERSION_CODES.O)    public void createNoticficationChannel(String channelId,String channelName,int importance){         NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);         NotificationChannel channel = new NotificationChannel(channelId,channelName,importance);         channel.setShowBadge(true);//是否显示角标未读数         manager.createNotificationChannel(channel);    }    //发送聊天消息    public void sendChatMsg(View v){        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        //判断当前渠道是否被关闭        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){            NotificationChannel channel = manager.getNotificationChannel("chat");            if(channel.getImportance() == NotificationManager.IMPORTANCE_NONE){                Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);                intent.putExtra(Settings.EXTRA_APP_PACKAGE,getPackageName());                intent.putExtra(Settings.EXTRA_CHANNEL_ID,channel.getId());                startActivity(intent);                Toast.makeText(this,"请手动打开通知",Toast.LENGTH_SHORT).show();            }        }        Notification notification = new NotificationCompat.Builder(this,"chat")                .setContentTitle("受到了一条聊天消息")                .setContentText("你今天中午吃饭了吗?")                .setWhen(System.currentTimeMillis())                .setSmallIcon(R.drawable.ic_launcher_foreground)                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_foreground))                .setNumber(15) //设置角标未读数                .setAutoCancel(true)                .build();        manager.notify(1,notification);    }    //发送订阅消息    public void sendSubscribeMsg(View v){       NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);       Notification notification = new NotificationCompat.Builder(this,"subscribe")               .setContentTitle("接收到了一条订阅消息")               .setContentText("武汉长江大桥将在9月份开通")               .setWhen(System.currentTimeMillis())               .setSmallIcon(R.drawable.ic_launcher_foreground)               .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_foreground))               .setNumber(10)               .setAutoCancel(true)               .build();        manager.notify(2,notification);    }}

 

转载于:https://my.oschina.net/quguangle/blog/1819858

你可能感兴趣的文章
[转]Centos配置国内yum源
查看>>
redis数据类型和应用场景
查看>>
Spring IOC
查看>>
Fragment的onCreateView和onActivityCreate之间的区别(转)
查看>>
AC日记——统计难题 hdu 1251
查看>>
在仿真器中运行时跳过Windows Azure Startup任务
查看>>
android 获取路径目录方法以及判断目录是否存在,创建目录
查看>>
数列问题[HAOI2004模拟]
查看>>
2012各大IT公司校招笔试题整理
查看>>
phpcms 后台分页
查看>>
《需求工程》阅读笔记之六
查看>>
架构阅读笔记5
查看>>
IIS5.1使用虚拟目录部署网站
查看>>
Git 深度学习填坑之旅三(分支branch、远程操作)
查看>>
括号匹配问题
查看>>
UVA 10766 Organising the Organisation
查看>>
「美团 CodeM 复赛」城市网络
查看>>
python 将Excel表格中的一列数据转化成多行数据
查看>>
Go多线程与channel通信
查看>>
找水王
查看>>