Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SmartCloudAppNotificationService
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baijinqiu
SmartCloudAppNotificationService
Commits
9f390881
Commit
9f390881
authored
Jun 13, 2020
by
TakeItEasyJQ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交代码
parent
56700e47
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
src/android/ONService.java
+26
-6
No files found.
src/android/ONService.java
View file @
9f390881
package
com
.
orhon
.
notification
;
package
com
.
orhon
.
notification
;
import
android.app.ActivityManager
;
import
android.app.Service
;
import
android.app.Service
;
import
android.content.ComponentName
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.ServiceConnection
;
import
android.content.ServiceConnection
;
import
android.os.IBinder
;
import
android.os.IBinder
;
...
@@ -15,6 +17,9 @@ import org.apache.cordova.CallbackContext;
...
@@ -15,6 +17,9 @@ import org.apache.cordova.CallbackContext;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
java.util.List
;
/**
/**
* This class echoes a string called from JavaScript.
* This class echoes a string called from JavaScript.
*/
*/
...
@@ -87,12 +92,14 @@ public class ONService extends CordovaPlugin {
...
@@ -87,12 +92,14 @@ public class ONService extends CordovaPlugin {
// 接触activity与service的绑定(最好在退出时调用)
// 接触activity与service的绑定(最好在退出时调用)
if
(
action
.
equals
(
"unbindService"
))
{
if
(
action
.
equals
(
"unbindService"
))
{
cordova
.
getActivity
().
runOnUiThread
(
new
Runnable
()
{
if
(
isServiceExisted
(
NotificationService
.
class
.
getName
())){
@Override
cordova
.
getActivity
().
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
@Override
cordova
.
getActivity
().
unbindService
(
connection
);
public
void
run
()
{
}
cordova
.
getActivity
().
unbindService
(
connection
);
});
}
});
}
}
}
return
false
;
return
false
;
}
}
...
@@ -104,4 +111,17 @@ public class ONService extends CordovaPlugin {
...
@@ -104,4 +111,17 @@ public class ONService extends CordovaPlugin {
callbackContext
.
error
(
"Expected one non-empty string argument."
);
callbackContext
.
error
(
"Expected one non-empty string argument."
);
}
}
}
}
public
boolean
isServiceExisted
(
String
className
)
{
ActivityManager
am
=
(
ActivityManager
)
cordova
.
getActivity
().
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
List
<
ActivityManager
.
RunningServiceInfo
>
serviceList
=
am
.
getRunningServices
(
Integer
.
MAX_VALUE
);
int
myUid
=
android
.
os
.
Process
.
myUid
();
for
(
ActivityManager
.
RunningServiceInfo
runningServiceInfo
:
serviceList
)
{
if
(
runningServiceInfo
.
uid
==
myUid
&&
runningServiceInfo
.
service
.
getClassName
().
equals
(
className
))
{
return
true
;
}
}
return
false
;
}
}
}
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