瀏覽代碼

1.增加换起通知设置

tags/0.0.13+2
“yanghuaxuan” 3 年之前
父節點
當前提交
c3e5f821ad
共有 4 個文件被更改,包括 105 次插入54 次删除
  1. +48
    -0
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java
  2. +47
    -31
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart
  3. +9
    -22
      lib/pages/home_page/home_page.dart
  4. +1
    -1
      pubspec.yaml

+ 48
- 0
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java 查看文件

@@ -1,13 +1,16 @@
package cn.zhios.zhiying_base_widget_example;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
@@ -184,12 +187,57 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN
removeLaunchView();
}



@Override
protected void onDestroy() {
super.onDestroy();
ZhiyingFlutterCommNative.getInstance().unregist();
}

@Override
public void openAppSettings(){
Context context=getActivity();
try {
Intent localIntent = new Intent();
///< 直接跳转到应用通知设置的代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
localIntent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
localIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
localIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
localIntent.putExtra("app_package", context.getPackageName());
localIntent.putExtra("app_uid", context.getApplicationInfo().uid);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
localIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
localIntent.addCategory(Intent.CATEGORY_DEFAULT);
localIntent.setData(Uri.parse("package:" + context.getPackageName()));
} else {
///< 4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
}
context.startActivity(localIntent);
} catch (Exception ex) {

try {
Intent settingsIntent = new Intent();
settingsIntent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
settingsIntent.addCategory(Intent.CATEGORY_DEFAULT);
settingsIntent.setData(android.net.Uri.parse("package:" + context.getPackageName()));
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(settingsIntent);

} catch (Exception exw) {

}
}
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);


+ 47
- 31
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart 查看文件

@@ -1,43 +1,58 @@
import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_model.dart';
import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart';
import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'dart:convert' as convert;
import 'package:package_info/package_info.dart';

class NotificationSettingDialog extends StatelessWidget {

final NotificationSettingModel model;

const NotificationSettingDialog(this.model, {Key key}) : super(key: key);

static Future show(BuildContext context) async {

Map result =
await NetUtil.post('/api/v1/mod/pub.flutter.push_dialog', method: NetMethod.GET);
Map result = await NetUtil.post('/api/v1/mod/pub.flutter.push_dialog', method: NetMethod.GET);
if (!EmptyUtil.isEmpty(result)) {
var modListData = result['data']['mod_list'][0]['data'];
if (!EmptyUtil.isEmpty(modListData)) {
// return EmptyPageModel.fromJson(jsonDecode(modListData));
//
// String d = json['data']['data'];
Map<String, dynamic> da =
Map<String, dynamic>.from(convert.jsonDecode(modListData));
Map<String, dynamic> da = Map<String, dynamic>.from(convert.jsonDecode(modListData));
NotificationSettingModel model = NotificationSettingModel.fromJson(Map<String, dynamic>.from(da));

await showCupertinoDialog(
context: context, builder: (_) => NotificationSettingDialog(model));
await showCupertinoDialog(context: context, builder: (_) => NotificationSettingDialog(model));

PermissionStatus status = await Permission.notification.status;
if (status != PermissionStatus.granted) {
if (!await Permission.notification.isGranted) {
await Permission.notification.request();
if (await Permission.notification.isDenied) {
var packageInfo = await PackageInfo.fromPlatform();
await showDialog(
context: context,
child: TipDialog(
btnText: "去打开",
content: "系统检查到您还未开启通知权限,可通过以下指引打开通知权限\n 设置 -> 应用管理 -> " + (packageInfo?.appName ?? "") + " -> 通知管理",
));

if (Platform.isAndroid) {
NativeUtil.openAppSettings();
} else {
openAppSettings();
}
}
}

if (!await Permission.storage.isGranted) {
await Permission.storage.request();
}
}
}

}

@override
@@ -62,20 +77,16 @@ class NotificationSettingDialog extends StatelessWidget {
Stack(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)),
child: CachedNetworkImage(
fit: BoxFit.fitWidth,
imageUrl:
model?.bgStackImg ?? '',
imageUrl: model?.bgStackImg ?? '',
),
),
Transform.translate(
offset: Offset(0, -15),
child: CachedNetworkImage(
imageUrl:
model?.bgOnStackImg ?? '',
imageUrl: model?.bgOnStackImg ?? '',
),
),
],
@@ -92,8 +103,7 @@ class NotificationSettingDialog extends StatelessWidget {
),
),
Padding(
padding:
const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4),
padding: const EdgeInsets.only(left: 8.0, right: 8.0, bottom: 4),
child: Text(
model?.subtitle ?? '',
style: TextStyle(
@@ -103,12 +113,13 @@ class NotificationSettingDialog extends StatelessWidget {
),
),
),
Column(children: model?.list.map((e) => _createItem(e)).toList() ?? [],),
Column(
children: model?.list.map((e) => _createItem(e)).toList() ?? [],
),
GestureDetector(
onTap: () async {
// 检查并请求权限
PermissionStatus status =
await Permission.notification.request();
PermissionStatus status = await Permission.notification.request();
if (status == PermissionStatus.denied) {
await openAppSettings();
} else if (status != PermissionStatus.granted) {
@@ -121,7 +132,9 @@ class NotificationSettingDialog extends StatelessWidget {
margin: EdgeInsets.only(top: 10, bottom: 10),
width: 120,
height: 60,
child: CachedNetworkImage(imageUrl: model?.btnImg ?? '',),
child: CachedNetworkImage(
imageUrl: model?.btnImg ?? '',
),
),
)
],
@@ -132,7 +145,9 @@ class NotificationSettingDialog extends StatelessWidget {
width: 30,
height: 30,
margin: EdgeInsets.only(top: 10),
child: CachedNetworkImage(imageUrl: model?.deleteImg ?? '',),
child: CachedNetworkImage(
imageUrl: model?.deleteImg ?? '',
),
),
onTap: () {
Navigator.pop(context);
@@ -152,11 +167,12 @@ class NotificationSettingDialog extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(right: 6, top: 2),
width: 20,
height: 20,
child: CachedNetworkImage(imageUrl: itemModel?.icon ?? '',)
),
margin: EdgeInsets.only(right: 6, top: 2),
width: 20,
height: 20,
child: CachedNetworkImage(
imageUrl: itemModel?.icon ?? '',
)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,


+ 9
- 22
lib/pages/home_page/home_page.dart 查看文件

@@ -356,29 +356,7 @@ class _HomePageState extends LifeState<HomePage> with WidgetsBindingObserver, Ti
/// 3、活动弹窗
///
Future _showPolicy() async {
// 通知弹窗

if (!await Permission.notification.isGranted) {
await NotificationSettingDialog.show(context);
}

// 活动弹窗
await AdvertisingDialog.show(context);

if (!await Permission.storage.isGranted) {
var result = await showDialog(
context: context,
child: TipDialog(
content: "为了节省网络流量,我们需要获取本地存储权限,缓存信息数据。",
));
if (result != null && result) {
await Permission.storage.request();
// 初始化百川sdk
FlutterAlibc.initAlibc(version: "", appName: "").then((result) async {
Logger.debug('初始化百川sdk ${result.errorCode} ${result.errorMessage}');
});
}
}

await Future.delayed(Duration(milliseconds: 600), () async {
//debug app不更新 app更新插件
@@ -387,6 +365,15 @@ class _HomePageState extends LifeState<HomePage> with WidgetsBindingObserver, Ti
await AppUpdateUtil.updateApp(context);
});

// 通知弹窗

if (!await Permission.notification.isGranted || !await Permission.storage.isGranted) {
await NotificationSettingDialog.show(context);
}

// 活动弹窗
await AdvertisingDialog.show(context);

IntellectCreate.checkAndCreateFirst(context);
}



+ 1
- 1
pubspec.yaml 查看文件

@@ -39,7 +39,7 @@ dependencies:
# image_gallery_saver: ^1.6.0
permission_handler:
git:
ref: 0.0.1
ref: 0.0.2
url: http://192.168.0.138:3000/FnuoOS_Flutter_Components/permission_handler.git

more_picture_share:


Loading…
取消
儲存