1涩馆、部分手機無法啟動通知權(quán)限手動啟動
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
settingPermission();//設(shè)置通知權(quán)限8.0/9.0
}
/**
* 設(shè)置通知權(quán)限8.0/9.0
*/
private void settingPermission() {
if (!checkNotifySetting()){
try {
// 根據(jù)isOpened結(jié)果肢预,判斷是否需要提醒用戶跳轉(zhuǎn)AppInfo頁面,去打開App通知權(quán)限
? ? ? ? ? ? Intent intent =new Intent();
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
//這種方案適用于 API 26, 即8.0(含8.0)以上可以用
? ? ? ? ? ? intent.putExtra(EXTRA_APP_PACKAGE, getPackageName());
intent.putExtra(EXTRA_CHANNEL_ID, getApplicationInfo().uid);
//這種方案適用于 API21——25,即 5.0——7.1 之間的版本可以使用
? ? ? ? ? ? intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);
// 小米6 -MIUI9.6-8.0.0系統(tǒng)拄氯,是個特例绳矩,通知設(shè)置界面只能控制"允許使用通知圓點"——然而這個玩意并沒有卵用,我想對雷布斯說:I'm not ok!!!
//? if ("MI 6".equals(Build.MODEL)) {
//? ? ? intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
//? ? ? Uri uri = Uri.fromParts("package", getPackageName(), null);
//? ? ? intent.setData(uri);
//? ? ? // intent.setAction("com.android.settings/.SubSettings");
//? }
? ? ? ? ? ? startActivity(intent);
}catch (Exception e) {
e.printStackTrace();
// 出現(xiàn)異常則跳轉(zhuǎn)到應(yīng)用設(shè)置界面:錘子堅果3——OC105 API25
? ? ? ? ? ? Intent intent =new Intent();
//下面這種方案是直接跳轉(zhuǎn)到當(dāng)前應(yīng)用的設(shè)置界面赫舒。
//https://blog.csdn.net/ysy950803/article/details/71910806
? ? ? ? ? ? intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(),null);
intent.setData(uri);
startActivity(intent);
}
}
}
private boolean checkNotifySetting() {
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
// areNotificationsEnabled方法的有效性官方只最低支持到API 19,低于19的仍可調(diào)用此方法不過只會返回true闽瓢,即默認(rèn)為用戶已經(jīng)開啟了通知接癌。
? ? ? ? boolean isOpened = manager.areNotificationsEnabled();
//? ? ? ? if (isOpened) {
//? ? ? ? ? ToastUtils.showShort(this,"通知權(quán)限開啟成功");
//
//? ? ? ? } else {
////? ? ? ? ? ? ToastUtils.showShort(this,"還沒有開啟通知權(quán)限,點擊去開啟");
//? ? ? ? }
? ? ? ? return isOpened;
}
2扣讼、動態(tài)配置廣播(在build.gradle中 adnroid-buildTypes下配置信息 ):
1缺猛、動態(tài)配置
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
intentFilter =new IntentFilter()
? ? ? ? ? ? intentFilter.addAction(getString(R.string.getui_action,BuildConfig.GETUI_APP_ID));
receiver =new GexinMsgReceiver();
registerReceiver(receiver,intentFilter);
}
2、action信息動態(tài)配置
buildTypes {
debug {
buildConfigField"boolean","LOG_DEBUG","true"
? ? ? ? proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.txt'
? ? ? ? versionType ="debug"
? ? ? ? signingConfig signingConfigs.signingConfig
manifestPlaceholders = [
GETUI_APP_ID? ? :"xxxxxxxxxxx",
GETUI_APP_KEY? :"xxxxxxxxxxx",
GETUI_APP_SECRET:"xxxxxxxxxxx"
? ? ? ? ]
buildConfigField"String","GETUI_APP_ID","\"${manifestPlaceholders.GETUI_APP_ID}\""http://個推ID
? ? }
release {
buildConfigField"boolean","LOG_DEBUG","false"
? ? ? ? minifyEnabledtrue
? ? ? ? shrinkResourcestrue
? ? ? ? zipAlignEnabledtrue
? ? ? ? signingConfig signingConfigs.signingConfig
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.txt'
? ? ? ? versionType ="release"
? ? ? ? manifestPlaceholders = [
GETUI_APP_ID? ? :"xxxxxxxxxxx",
GETUI_APP_KEY? :"xxxxxxxxxxx",
GETUI_APP_SECRET:"xxxxxxxxxxx"
? ? ? ? ]
buildConfigField"String","GETUI_APP_ID","\"${manifestPlaceholders.GETUI_APP_ID}\""http://個推ID
? ? }
}