Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CarEnter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨秀秀
CarEnter
Commits
429cdd0c
Commit
429cdd0c
authored
Feb 21, 2025
by
david
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.增加通知权限申请
parent
cefa327d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
LoginActivity.java
...main/java/com/xxp/carEnter/ui/activity/LoginActivity.java
+45
-0
No files found.
app/src/main/java/com/xxp/carEnter/ui/activity/LoginActivity.java
View file @
429cdd0c
...
...
@@ -3,6 +3,7 @@ package com.xxp.carEnter.ui.activity;
import
android.Manifest
;
import
android.app.AlertDialog
;
import
android.app.DownloadManager
;
import
android.app.NotificationManager
;
import
android.app.ProgressDialog
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
...
...
@@ -17,6 +18,7 @@ import android.os.Build;
import
android.os.Environment
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.provider.Settings
;
import
android.text.InputType
;
import
android.text.TextUtils
;
import
android.util.Log
;
...
...
@@ -27,6 +29,7 @@ import android.widget.EditText;
import
android.widget.ImageView
;
import
android.widget.Toast
;
import
androidx.annotation.RequiresApi
;
import
androidx.core.content.FileProvider
;
import
com.xxp.carEnter.Date.SharedPreferencesUtils
;
...
...
@@ -310,6 +313,7 @@ public class LoginActivity extends xxBaseActivity implements LoginView {
finish
();
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N
)
@Override
public
void
navigateToVersion
(
String
versionCode
)
{
knownVersion
=
versionCode
;
...
...
@@ -324,8 +328,16 @@ public class LoginActivity extends xxBaseActivity implements LoginView {
// 应用程序版本过旧,弹出更新提示框
showUpdateDialog
();
}
else
if
(
compareResult
==
0
)
{
boolean
flag
=
isNotificationEnabled
(
this
);
if
(!
flag
)
{
showNotificationAlertDialog
(
this
);
}
System
.
out
.
println
(
"应用程序版本已是最新!"
);
}
else
{
boolean
flag
=
isNotificationEnabled
(
this
);
if
(!
flag
)
{
showNotificationAlertDialog
(
this
);
}
System
.
out
.
println
(
"应用程序版本较新!"
);
}
}
...
...
@@ -443,4 +455,37 @@ public class LoginActivity extends xxBaseActivity implements LoginView {
public
void
onPointerCaptureChanged
(
boolean
hasCapture
)
{
super
.
onPointerCaptureChanged
(
hasCapture
);
}
// 检查通知权限是否被开启
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N
)
public
boolean
isNotificationEnabled
(
Context
context
)
{
NotificationManager
notificationManager
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
return
notificationManager
!=
null
&&
notificationManager
.
areNotificationsEnabled
();
}
// 显示提示对话框
public
void
showNotificationAlertDialog
(
Context
context
)
{
new
AlertDialog
.
Builder
(
context
)
.
setTitle
(
"开启通知"
)
.
setMessage
(
"请在设置中开启通知以接收重要信息"
)
.
setPositiveButton
(
"去设置"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
// 这里可以引导用户到设置页面
goToNotificationSettings
(
context
);
}
})
.
setNegativeButton
(
"取消"
,
null
)
.
show
();
}
// 引导用户到系统设置以开启通知
public
void
goToNotificationSettings
(
Context
context
)
{
Intent
intent
=
new
Intent
();
intent
.
setAction
(
Settings
.
ACTION_APP_NOTIFICATION_SETTINGS
);
intent
.
putExtra
(
Settings
.
EXTRA_APP_PACKAGE
,
context
.
getPackageName
());
context
.
startActivity
(
intent
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment