-
Notifications
You must be signed in to change notification settings - Fork 0
/
GMPlugin.java
43 lines (34 loc) · 1.25 KB
/
GMPlugin.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
package com.phonegap.plugin;
import org.json.JSONArray;
import android.content.Intent;
import android.util.Log;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
public class GMPlugin extends Plugin {
public static int GET_GEONAME_URL = 0;
public static int RESULT_OK = 0;
private String callbackId;
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult result = null;
this.callbackId = callbackId;
if(action.compareTo("startGM") == 0) {
Intent intent = new Intent(ctx.getContext(), GMActivity.class);
ctx.startActivityForResult((Plugin) this, intent, GET_GEONAME_URL);
result = new PluginResult(PluginResult.Status.NO_RESULT);
result.setKeepCallback(true);
}
return result;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(requestCode == GET_GEONAME_URL && intent != null) {
if(resultCode == RESULT_OK) {
Log.d("NearMePlugin", intent.getExtras().getString("wikipediaUrl"));
this.success(new PluginResult(PluginResult.Status.OK, intent.getExtras().getString("wikipediaUrl")), callbackId);
}
} else {
this.success(new PluginResult(PluginResult.Status.NO_RESULT), callbackId);
}
}
}