-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFloatingActivityPlugin.java
63 lines (56 loc) · 1.64 KB
/
FloatingActivityPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.phonegap.plugins.FloatingActivityPlugin;
import org.apache.cordova.api.*;
import org.apache.cordova.example.ChatHeadService;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
/**
* Plugin to launch Services, Activity as Seperate Thread
*
* @author Abraham.K <abrahamrkj@gmail.com>
* @website abrahamk.in
* @license MIT/X11
*/
public class FloatingActivityPlugin extends CordovaPlugin {
FloatingActivityPlugin _theApp;
ComponentName _checkerService;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
// TODO Auto-generated method stub
Context context = cordova.getActivity().getApplicationContext();
PackageManager pm = cordova.getActivity().getPackageManager();
_checkerService = null;
String packageName;
Boolean result = true;
try {
packageName = args.getString(0);
} catch (JSONException e) {
return false;
}
result = launch(pm,context,packageName, context);
if (result == true) {
callbackContext.success(0);
return true;
} else {
callbackContext.error(0);
return false;
}
}
public boolean launch(PackageManager pm, Context c, String packname , final Context con)
{
if(_checkerService==null){
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
_checkerService = cordova.getActivity().startService(new Intent(con, ChatHeadService.class));
}
});
t.start();
}
return true;
}
}