📎 AndroidNative【ING...】

1. 获取手机通讯录时:

(1)如果配置文件中已经添加了读写权限,依然报错以下ERROR;

ERROR报错:requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTAC

      读写permission问题,可能出现的原因,手机、模拟器未对此应用开启通讯录权限。

2. Notification:

(1)此notification在 =》 【安卓系统8 及以上那么要使用通知的新特性:通知通道 】;其他则通过 new NotificationCompat.Builder(this).set....进行属性设置。

e.g. 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 安卓8.0以上的声音从 mChannel中的最后一个参数NotificationManager.IMPORTANCE_DEFAULT
NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH);
// ...
  


}

(2)SOUND铃声

(2.1)自定义铃声:一定要在NotificationManager.createNotificationChannel(cannel)创建cannel之前setSound(自定义铃声内容,  默认铃声);

e.g.  

mChannel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wowhere), Notification.AUDIO_ATTRIBUTES_DEFAULT);

(2.2)铃声播放:notification.flags = 对flags进行设置如下:

          notification.flags |= Notification.FLAG_AUTO_CANCEL;
      /*
        *
        * FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉 自动播放一遍然后停止播放
        FLAG_NO_CLEAR 该通知能被状态栏的清除按钮给清除掉
        FLAG_ONGOING_EVENT 通知放置在正在运行
        FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应
        *
       */

  (3) notification的提示呼吸灯、震动频率次数设置:与(1)的系统判定使用方法原理相同,如果是安卓8及以上系统,那么需要在通知通道中设置呼吸灯的颜色。

e.g. (3.1)如果是安卓系统8及以上:

      // 设置通知出现时的闪灯(如果 android 设备支持的话)
        mChannel.shouldShowLights();
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.BLUE); // !!! 在通道里面设置通知灯的颜色。
      // 如设置,那么通知出现时也会出现震动(如果 android 设备支持的话)
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(new long[]{1000, 2000, 1000, 3000}); //静止1秒,震动2秒,静止1秒,震动3秒
(3.2)
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notification.defaults |= Notification.DEFAULT_LIGHTS;

  (4)

  (5)



原文地址:https://www.cnblogs.com/little-bee-fly/p/10813201.html