Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
D
Daemon_App
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
胡江林
Daemon_App
Commits
d791cf20
Commit
d791cf20
authored
Aug 10, 2022
by
胡江林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开机时启动自己服务即可。
parent
3fc9ca83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
50 deletions
+10
-50
app/src/main/java/com/youbay/daemon/BootReceiver.java
app/src/main/java/com/youbay/daemon/BootReceiver.java
+10
-50
No files found.
app/src/main/java/com/youbay/daemon/BootReceiver.java
View file @
d791cf20
package
com
.
youbay
.
daemon
;
package
com
.
youbay
.
daemon
;
import
android.app.ActivityManager
;
import
android.app.ActivityManager.RunningServiceInfo
;
import
android.content.BroadcastReceiver
;
import
android.content.BroadcastReceiver
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Build
;
import
android.os.Build
;
...
@@ -12,59 +9,22 @@ import android.os.Build;
...
@@ -12,59 +9,22 @@ import android.os.Build;
* @author Administrator
* @author Administrator
*/
*/
public
class
BootReceiver
extends
BroadcastReceiver
{
public
class
BootReceiver
extends
BroadcastReceiver
{
static
final
String
ACTION_BOOT
=
"android.intent.action.BOOT_COMPLETED"
;
static
final
String
ACTION_SMDT
=
"android.intent.action.SMDT_BOOT_COMPLETED"
;
static
final
String
ACTION_SMDT
=
"android.intent.action.SMDT_BOOT_COMPLETED"
;
static
final
String
ACTION_AUDIO
=
"android.media.AUDIO_BECOMING_NOISY"
;
private
static
final
String
APP_PACKAGE_NAME
=
"com.youbay.classcard"
;
private
static
final
String
DAEMON_SERVICE_NAME
=
"com.youbay.classcard.service.DaemonService"
;
private
static
final
String
DAEMON_SERVICE_ACTION
=
"com.youbay.classcard.service.DaemonService"
;
@Override
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
if
(
ACTION_BOOT
.
equals
(
intent
.
getAction
()))
{
if
(
intent
==
null
)
{
System
.
out
.
println
(
"-------------BOOT_COMPLETED----------------"
);
return
;
startIntent
(
context
);
}
else
if
(
ACTION_SMDT
.
equals
(
intent
.
getAction
()))
{
System
.
out
.
println
(
"-------------SMDT_BOOT_COMPLETED----------------"
);
startIntent
(
context
);
}
else
if
(
ACTION_AUDIO
.
equals
(
intent
.
getAction
()))
{
System
.
out
.
println
(
"-------------AUDIO_BECOMING_NOISY----------------"
);
startIntent
(
context
);
}
}
private
void
startIntent
(
Context
context
)
{
/*if (isServiceRunning(context)) {
System.out.println("this daemon service is running ..");
} else {
final Intent daemonIntent = new Intent();
daemonIntent.setAction(DAEMON_SERVICE_ACTION);
daemonIntent.setComponent(new ComponentName(APP_PACKAGE_NAME, DAEMON_SERVICE_NAME));
context.startService(daemonIntent);
}*/
final
Intent
daemonIntent
=
new
Intent
();
daemonIntent
.
setAction
(
DAEMON_SERVICE_ACTION
);
daemonIntent
.
setComponent
(
new
ComponentName
(
APP_PACKAGE_NAME
,
DAEMON_SERVICE_NAME
));
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
context
.
startForegroundService
(
daemonIntent
);
}
else
{
context
.
startService
(
daemonIntent
);
}
}
}
String
action
=
intent
.
getAction
();
if
(
Intent
.
ACTION_BOOT_COMPLETED
.
equals
(
action
)
||
ACTION_SMDT
.
equals
(
action
))
{
private
boolean
isServiceRunning
(
Context
context
)
{
System
.
out
.
println
(
"-------------BOOT_COMPLETED----------------"
);
ActivityManager
manager
=
(
ActivityManager
)
context
//startIntent(context);
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
for
(
RunningServiceInfo
service
:
manager
context
.
startForegroundService
(
new
Intent
(
context
,
DaemonService
.
class
));
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
}
else
{
if
(
DaemonService
.
class
.
getName
().
equals
(
context
.
startService
(
new
Intent
(
context
,
DaemonService
.
class
));
service
.
service
.
getClassName
()))
{
return
true
;
}
}
}
}
return
false
;
}
}
}
}
\ No newline at end of file
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