Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
B
Browser White
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
Browser White
Commits
c3cd7169
Commit
c3cd7169
authored
Aug 07, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
4c1ec836
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
321 additions
and
0 deletions
+321
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+9
-0
StayNotificationService.kt
.../com/base/browserwhite/service/StayNotificationService.kt
+178
-0
HomeFragment.kt
...in/java/com/base/browserwhite/ui/fragment/HomeFragment.kt
+4
-0
fragment_home.xml
app/src/main/res/layout/fragment_home.xml
+1
-0
stay_notification_big.xml
app/src/main/res/layout/stay_notification_big.xml
+129
-0
tishi.png
app/src/main/res/mipmap-xxhdpi/tishi.png
+0
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
c3cd7169
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
xmlns:tools=
"http://schemas.android.com/tools"
>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE_DATA_SYNC"
/>
<application
<application
android:allowBackup=
"true"
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:dataExtractionRules=
"@xml/data_extraction_rules"
...
@@ -52,6 +55,12 @@
...
@@ -52,6 +55,12 @@
android:launchMode=
"singleTop"
android:launchMode=
"singleTop"
android:screenOrientation=
"portrait"
android:screenOrientation=
"portrait"
tools:ignore=
"DiscouragedApi,LockedOrientationActivity"
/>
tools:ignore=
"DiscouragedApi,LockedOrientationActivity"
/>
<service
android:name=
".service.StayNotificationService"
android:foregroundServiceType=
"dataSync"
/>
</application>
</application>
</manifest>
</manifest>
\ No newline at end of file
app/src/main/java/com/base/browserwhite/service/StayNotificationService.kt
0 → 100644
View file @
c3cd7169
package
com.base.browserwhite.service
import
android.app.Notification
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.PendingIntent
import
android.app.Service
import
android.content.Context
import
android.content.Intent
import
android.content.pm.ServiceInfo
import
android.graphics.BitmapFactory
import
android.graphics.drawable.Icon
import
android.os.Build
import
android.os.IBinder
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
com.base.browserwhite.R
import
com.base.browserwhite.service.StayNotificationService.Companion.startStayNotification
import
com.base.browserwhite.ui.activity.MainActivity
import
kotlin.random.Random
/**
* 常驻通知栏
*/
class
StayNotificationService
:
Service
()
{
private
val
TAG
=
"StayNotificationService"
companion
object
{
var
isRunning
=
false
fun
Context
.
startStayNotification
()
{
val
intent
=
Intent
(
this
,
StayNotificationService
::
class
.
java
)
if
(
Build
.
VERSION
.
SDK_INT
>
Build
.
VERSION_CODES
.
TIRAMISU
)
{
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
startForegroundService
(
intent
)
}
else
{
startService
(
intent
)
}
}
fun
Context
.
restartStartStayNotification
()
{
val
intent
=
Intent
(
this
,
StayNotificationService
::
class
.
java
)
stopService
(
intent
)
startStayNotification
()
}
}
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
if
(!
isRunning
)
{
startForeground
()
}
return
START_STICKY
}
private
fun
startForeground
()
{
val
notification
=
createPermanentNotification
(
applicationContext
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
{
startForeground
(
1
,
notification
,
ServiceInfo
.
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
}
else
{
startForeground
(
1
,
notification
)
}
isRunning
=
true
}
override
fun
onBind
(
intent
:
Intent
?):
IBinder
?
{
return
null
}
override
fun
onDestroy
()
{
isRunning
=
false
super
.
onDestroy
()
}
private
fun
createPermanentNotification
(
context
:
Context
):
Notification
{
val
isOngoing
=
true
//是否持续(为不消失的常驻通知)
val
channelName
=
"File Recovery Foreground Service Channel"
val
channelId
=
"File_Recovery_Service_Id"
val
category
=
Notification
.
CATEGORY_SERVICE
val
contentView
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
stay_notification_big
)
val
expendView
=
RemoteViews
(
context
.
packageName
,
R
.
layout
.
stay_notification_big
)
val
requestCode1
=
Random
.
nextInt
(
1800
)
val
intent0
=
Intent
(
context
,
MainActivity
::
class
.
java
).
apply
{
}
val
pendingIntent0
=
PendingIntent
.
getActivity
(
context
,
requestCode1
,
intent0
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
id_ll_clean
,
pendingIntent0
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
id_ll_clean
,
pendingIntent0
)
val
requestCode2
=
Random
.
nextInt
(
1800
)
val
intent2
=
Intent
(
context
,
MainActivity
::
class
.
java
).
apply
{
// putExtra("actionId", ConstObject.ID_RECOVERY_PHOTOS)
// putExtra("ScanType", SCAN_PHOTOS)
}
val
pendingIntent2
=
PendingIntent
.
getActivity
(
context
,
requestCode2
,
intent2
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_photos
,
pendingIntent2
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_photos
,
pendingIntent2
)
val
requestCode3
=
Random
.
nextInt
(
1800
)
val
intent3
=
Intent
(
context
,
MainActivity
::
class
.
java
).
apply
{
// putExtra("actionId", ConstObject.ID_RECOVERY_VIDEOS)
// putExtra("ScanType", SCAN_VIDEOS)
}
val
pendingIntent3
=
PendingIntent
.
getActivity
(
context
,
requestCode3
,
intent3
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_videos
,
pendingIntent3
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_videos
,
pendingIntent3
)
// val intent4 = Intent()
// val serviceComponent = ComponentName(context, FlashlightService::class.java)
// intent4.component = serviceComponent
// val pendingIntent4 =
// PendingIntent.getService(context, 0, intent4, PendingIntent.FLAG_IMMUTABLE)
// contentView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
// expendView.setOnClickPendingIntent(R.id.id_screenshot, pendingIntent4)
val
requestCode4
=
Random
.
nextInt
(
1800
)
val
intent4
=
Intent
(
context
,
MainActivity
::
class
.
java
).
apply
{
// putExtra("actionId", ConstObject.ID_RECOVERY_DOCUMENTS)
// putExtra("ScanType", SCAN_DOCUMENTS)
}
val
pendingIntent4
=
PendingIntent
.
getActivity
(
context
,
requestCode4
,
intent4
,
PendingIntent
.
FLAG_IMMUTABLE
)
contentView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_documents
,
pendingIntent4
)
expendView
.
setOnClickPendingIntent
(
R
.
id
.
id_recovery_documents
,
pendingIntent4
)
val
nfIntent
=
Intent
(
context
,
MainActivity
::
class
.
java
)
val
pendingIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
nfIntent
,
PendingIntent
.
FLAG_IMMUTABLE
)
val
builder
=
NotificationCompat
.
Builder
(
context
,
channelId
)
val
smallIcon
=
IconCompat
.
createFromIcon
(
context
,
Icon
.
createWithResource
(
this
,
R
.
mipmap
.
news
)
)
smallIcon
?.
let
{
builder
.
setSmallIcon
(
smallIcon
)
//设置状态栏内的小图标
}
builder
.
setLargeIcon
(
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
mipmap
.
news
))
builder
.
setContentTitle
(
context
.
resources
.
getString
(
R
.
string
.
app_name
))
builder
.
setContentIntent
(
pendingIntent
)
//设置PendingIntent
builder
.
setVisibility
(
NotificationCompat
.
VISIBILITY_PRIVATE
)
//设置通知公开可见
builder
.
setAutoCancel
(
false
)
builder
.
setPriority
(
NotificationCompat
.
PRIORITY_MAX
)
//优先级为:重要通知
builder
.
setWhen
(
System
.
currentTimeMillis
())
builder
.
setCustomContentView
(
contentView
)
builder
.
setCustomBigContentView
(
expendView
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
channel
=
NotificationChannel
(
channelId
,
channelName
,
NotificationManager
.
IMPORTANCE_LOW
)
channel
.
lockscreenVisibility
=
1
val
notificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
notificationManager
.
createNotificationChannel
(
channel
)
builder
.
setChannelId
(
channelId
)
}
return
builder
.
build
()
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/ui/fragment/HomeFragment.kt
View file @
c3cd7169
...
@@ -13,6 +13,7 @@ import com.base.browserwhite.bean.ConstObject.YAHOO
...
@@ -13,6 +13,7 @@ import com.base.browserwhite.bean.ConstObject.YAHOO
import
com.base.browserwhite.bean.ConstObject.YANDEX
import
com.base.browserwhite.bean.ConstObject.YANDEX
import
com.base.browserwhite.bean.WebSiteBean
import
com.base.browserwhite.bean.WebSiteBean
import
com.base.browserwhite.databinding.FragmentHomeBinding
import
com.base.browserwhite.databinding.FragmentHomeBinding
import
com.base.browserwhite.service.StayNotificationService.Companion.restartStartStayNotification
import
com.base.browserwhite.ui.activity.scanqrc.ScanQRCActivity
import
com.base.browserwhite.ui.activity.scanqrc.ScanQRCActivity
import
com.base.browserwhite.ui.activity.webstore.WevStoreActivity
import
com.base.browserwhite.ui.activity.webstore.WevStoreActivity
import
com.base.browserwhite.ui.adapter.WebsiteAdapter
import
com.base.browserwhite.ui.adapter.WebsiteAdapter
...
@@ -61,6 +62,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
...
@@ -61,6 +62,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
override
fun
setListener
()
{
override
fun
setListener
()
{
super
.
setListener
()
super
.
setListener
()
binding
.
llWeather
.
setOnClickListener
{
requireContext
().
restartStartStayNotification
()
}
binding
.
flSearchEngine
.
setOnClickListener
{
binding
.
flSearchEngine
.
setOnClickListener
{
requireContext
().
showSearchEngineDialog
{
website
->
requireContext
().
showSearchEngineDialog
{
website
->
...
...
app/src/main/res/layout/fragment_home.xml
View file @
c3cd7169
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
tools:ignore=
"HardcodedText"
/>
tools:ignore=
"HardcodedText"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/ll_weather"
android:layout_width=
"90dp"
android:layout_width=
"90dp"
android:layout_height=
"36dp"
android:layout_height=
"36dp"
android:layout_marginEnd=
"16dp"
android:layout_marginEnd=
"16dp"
...
...
app/src/main/res/layout/stay_notification_big.xml
0 → 100644
View file @
c3cd7169
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/bg_ffffff_10"
android:paddingVertical=
"4dp"
tools:ignore=
"DisableBaselineAlignment"
>
<!--清理-->
<LinearLayout
android:id=
"@+id/id_ll_clean"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:gravity=
"center"
android:orientation=
"vertical"
tools:ignore=
"UseCompoundDrawables"
>
<FrameLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
tools:ignore=
"UselessParent"
>
<ImageView
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_margin=
"2dp"
android:src=
"@mipmap/news"
tools:ignore=
"ContentDescription"
/>
<ImageView
android:layout_width=
"15dp"
android:layout_height=
"15dp"
android:layout_gravity=
"end"
android:src=
"@mipmap/tishi"
tools:ignore=
"ContentDescription"
/>
</FrameLayout>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
android:text=
"Clean"
android:textColor=
"#666666"
android:textSize=
"12sp"
tools:ignore=
"HardcodedText"
/>
</LinearLayout>
<!--恢复照片-->
<LinearLayout
android:id=
"@+id/id_recovery_photos"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:gravity=
"center"
android:orientation=
"vertical"
tools:ignore=
"UseCompoundDrawables"
>
<ImageView
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_marginBottom=
"6dp"
android:src=
"@mipmap/news"
tools:ignore=
"ContentDescription"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Photos"
android:textColor=
"#666666"
android:textSize=
"12sp"
tools:ignore=
"HardcodedText"
/>
</LinearLayout>
<!--恢复视频-->
<LinearLayout
android:id=
"@+id/id_recovery_videos"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:gravity=
"center"
android:orientation=
"vertical"
tools:ignore=
"UseCompoundDrawables"
>
<ImageView
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_marginBottom=
"6dp"
android:src=
"@mipmap/news"
tools:ignore=
"ContentDescription"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Videos"
android:textColor=
"#666666"
android:textSize=
"12sp"
tools:ignore=
"HardcodedText"
/>
</LinearLayout>
<!--恢复文档-->
<LinearLayout
android:id=
"@+id/id_recovery_documents"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:gravity=
"center"
android:orientation=
"vertical"
android:visibility=
"visible"
tools:ignore=
"UseCompoundDrawables"
>
<ImageView
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:layout_marginBottom=
"6dp"
android:src=
"@mipmap/news"
tools:ignore=
"ContentDescription"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Documents"
android:textColor=
"#666666"
android:textSize=
"12sp"
tools:ignore=
"HardcodedText"
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/mipmap-xxhdpi/tishi.png
0 → 100644
View file @
c3cd7169
3.18 KB
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