-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathJavaWebviewBridge.java
192 lines (164 loc) · 5.03 KB
/
JavaWebviewBridge.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.android.js.common;
import android.app.Activity;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import com.android.js.api.App;
import com.android.js.api.Call;
import com.android.js.api.Contact;
import com.android.js.api.DeepLink;
import com.android.js.api.Hotspot;
import com.android.js.api.Location;
import com.android.js.api.MobileData;
import com.android.js.api.Notification;
import com.android.js.api.SMS;
import com.android.js.api.Toast;
import com.android.js.api.Wifi;
import org.json.JSONException;
public class JavaWebviewBridge {
private Activity activity;
private WebView myWebView;
private Notification notification;
private Call call;
private Wifi wifi;
private Hotspot hotspot;
private Toast toast;
private App app;
private Contact contact;
private DeepLink deepLink;
private SMS sms;
private Location location;
private MobileData mobileData;
private int iconId;
private String className;
public JavaWebviewBridge(Activity activity, WebView myWebView, int iconId, String className){
this.activity = activity;
this.myWebView = myWebView;
this.notification = new Notification(activity, iconId, className);
this.call = new Call(activity);
this.wifi = new Wifi(activity);
this.hotspot = new Hotspot(activity);
this.toast = new Toast(activity);
this.app = new App(activity);
this.contact = new Contact(activity);
this.deepLink = new DeepLink(activity);
this.sms = new SMS(activity);
this.location = new Location(activity);
this.mobileData = new MobileData(activity);
this.iconId = iconId;
this.className = className;
this.className = className;
}
@JavascriptInterface
public String helloWorld(){
System.out.println("Java IPC Works");
return "Hello World";
}
@JavascriptInterface
public String getPath(String name) {
return app.getPath(name);
}
@JavascriptInterface
public String exec(String[] cmdarray) throws JSONException {
return app.exec(cmdarray);
}
@JavascriptInterface
public void initNotification(String title, String msg){
notification.initNotification(title, msg);
}
@JavascriptInterface
public void showNotification(int id){
notification.showNotification(id);
}
@JavascriptInterface
public void initBigNotification(String title, String [] msg){
notification.initBigNotification(title, msg);
}
@JavascriptInterface
public void showToast(String text, int duration){
toast.showToast(text, duration);
}
@JavascriptInterface
public void makeCall(String number){
call.makeCall(number);
}
@JavascriptInterface
public void enableWifi(){
wifi.enableWifi();
}
@JavascriptInterface
public void disableWifi(){
wifi.disableWifi();
}
@JavascriptInterface
public void disconnectWifi(){
wifi.disconnectWifi();
}
@JavascriptInterface
public int getWifiState(){
return wifi.getWifiState();
}
@JavascriptInterface
public boolean isWifiEnabled(){
return wifi.isWifiEnabled();
}
@JavascriptInterface
public String getWifiScanResults() throws JSONException {
return wifi.getWifiScanResults();
}
@JavascriptInterface
public void connectWifi(String ssid, String password){
wifi.connectWifi(ssid, password);
}
@JavascriptInterface
public void enableHotspot(String ssid){
try {
hotspot.enableHotspot(ssid);
}catch (Exception e){
e.printStackTrace();
}
}
@JavascriptInterface
public void disableHotspot(){
try{
hotspot.disableHotspot();
}catch (Exception e){
e.printStackTrace();
}
}
@JavascriptInterface
public boolean isHotspotEnabled(){
return hotspot.isHotspotEnabled();
}
@JavascriptInterface
public String getAllContacts() throws JSONException {
return this.contact.getAllContacts(false);
}
@JavascriptInterface
public String getContactByName(String name) throws JSONException {
return this.contact.getContactByName(name);
}
@JavascriptInterface
public int getContactsCount() throws JSONException {
return this.contact.getContactsCount();
}
@JavascriptInterface
public String addContact(String name, String number, String email) {
return this.contact.addContact(name, number, email);
}
@JavascriptInterface
public String getDeepLink(){
return this.deepLink.getLink();
}
@JavascriptInterface
public String sendSMS(String number, String message) {
return this.sms.sendSMS(number, message);
}
@JavascriptInterface
public String getLocation(){
return this.location.getLocation();
}
@JavascriptInterface
public boolean isMobileDataEnabled() {
return this.mobileData.isEnabled();
}
}