zoukankan      html  css  js  c++  java
  • Android Studio学习记录-第六周

    7.4.2 实现跨程序数据共享

    在ProviderTest中点击按钮不能实现打印日志的功能,目前还没有解决。

    8.2.1通知的基本用法

    按书中代码会报错;

          原因是Android 8.0 引入了通知渠道,targeSdk升级到26之后,所有的通知的实现都需要提供通知渠道,如果不提供通知渠道的话,所有通知在8.0系统上面都不能正常展示。

    MainActivity.java的代码如下

    public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    
        String id="channel_1";
        int importance = NotificationManager.IMPORTANCE_HIGH;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button sendNotice = (Button)findViewById(R.id.send_notice);
            sendNotice.setOnClickListener(this);
        }
        @Override
        public void onClick(View v){
            switch (v.getId()) {
                case R.id.send_notice:
                    NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                    NotificationChannel mchannel = new NotificationChannel(id,"test",importance);
                    manager.createNotificationChannel(mchannel);
                    Notification notification;
                    notification = new NotificationCompat.Builder(this,id)
                            .setContentTitle("This is content title")
                        .setContentText("This is content text")
                        .setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .build();
                    manager.notify(1, notification);
                    break;
                default:
                    break;
            }
        }
    }

    还需要在gradle文件中把minSdkVersion设成26;

    8.2.3通知的高级功能

    NotificationCompat.Builder的setSmallIcon在调用 ic_launcher 时没有效果,

    最终换成16*16像素的图才可以显示。

    8.3.1 调用摄像头拍照

    android.support.v4.content.FileProvider已经弃用

    应修改为

    androidx.core.content.FileProvider

    8.4.1播放音频

    点击play之后没有音乐响起,待解决。

  • 相关阅读:
    Consul常用命令
    ECharts 避免变窄
    TP3.2 日期默认格式
    新订单提示效果
    php 按照字典序排序 微信卡券签名算法用到
    td宽度自适应 窄的地方自动收缩
    git 删除本地分支,删除远程分支
    分页Model
    chrome表单自动填充如何取消
    tp3.2 如何比较两个字段
  • 原文地址:https://www.cnblogs.com/yangyangyang-xiannv/p/12236014.html
Copyright © 2011-2022 走看看