Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_push
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
顾海波
2025-01-24 09:18:53 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e0d5aaa68123754ccdd60767ec106dd6b7f41097
e0d5aaa6
1 parent
2c862db3
【需求】完善推送权限
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
7 deletions
android/src/main/kotlin/com/ewin/flutter_push/FlutterPushPlugin.kt
android/src/main/kotlin/com/ewin/flutter_push/utils/NotificationManagerUtils.java
android/src/main/kotlin/com/ewin/flutter_push/FlutterPushPlugin.kt
View file @
e0d5aaa
...
...
@@ -17,6 +17,7 @@ import com.mixpush.huawei.HuaweiPushProvider.HUAWEI
import com.ewin.flutter_push.EwinMixPushReceiver
import com.ewin.flutter_push.enums.MixListenerTypeEnum
import com.ewin.flutter_push.utils.CommonUtil
import com.ewin.flutter_push.utils.NotificationManagerUtils
import com.alibaba.fastjson.JSON
import com.mixpush.core.MixPushMessage
import android.content.ComponentName;
...
...
@@ -76,15 +77,10 @@ class FlutterPushPlugin: FlutterPlugin, MethodCallHandler {
})
result.success(true)
} else if(call.method == "checkPermission") {
result.success(NotificationManager
Compat.from(context).areNotificationsEnabled(
))
result.success(NotificationManager
Utils.isPermissionOpen(context
))
} else if(call.method == "getPermission") {
CommonUtil.runMainThread {
val intent = Intent().apply {
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
NotificationManagerUtils.openPermissionSetting(context)
}
result.success(true)
} else {
...
...
android/src/main/kotlin/com/ewin/flutter_push/utils/NotificationManagerUtils.java
0 → 100644
View file @
e0d5aaa
package
com
.
ewin
.
flutter_push
.
utils
;
import
android.app.NotificationManager
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.provider.Settings
;
import
androidx.core.app.NotificationManagerCompat
;
public
class
NotificationManagerUtils
{
public
static
boolean
isPermissionOpen
(
Context
context
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
return
NotificationManagerCompat
.
from
(
context
).
getImportance
()
!=
NotificationManager
.
IMPORTANCE_NONE
;
}
return
NotificationManagerCompat
.
from
(
context
).
areNotificationsEnabled
();
}
public
static
void
openPermissionSetting
(
Context
context
)
{
try
{
Intent
localIntent
=
new
Intent
();
localIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
//直接跳转到应用通知设置的代码:
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
localIntent
.
setAction
(
Settings
.
ACTION_APP_NOTIFICATION_SETTINGS
);
localIntent
.
putExtra
(
Settings
.
EXTRA_APP_PACKAGE
,
context
.
getPackageName
());
context
.
startActivity
(
localIntent
);
return
;
}
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
localIntent
.
setAction
(
"android.settings.APP_NOTIFICATION_SETTINGS"
);
localIntent
.
putExtra
(
"app_package"
,
context
.
getPackageName
());
localIntent
.
putExtra
(
"app_uid"
,
context
.
getApplicationInfo
().
uid
);
context
.
startActivity
(
localIntent
);
return
;
}
if
(
android
.
os
.
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
()));
context
.
startActivity
(
localIntent
);
return
;
}
//4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,
if
(
Build
.
VERSION
.
SDK_INT
>=
9
)
{
localIntent
.
setAction
(
"android.settings.APPLICATION_DETAILS_SETTINGS"
);
localIntent
.
setData
(
Uri
.
fromParts
(
"package"
,
context
.
getPackageName
(),
null
));
context
.
startActivity
(
localIntent
);
return
;
}
localIntent
.
setAction
(
Intent
.
ACTION_VIEW
);
localIntent
.
setClassName
(
"com.android.settings"
,
"com.android.setting.InstalledAppDetails"
);
localIntent
.
putExtra
(
"com.android.settings.ApplicationPkgName"
,
context
.
getPackageName
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment