forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShare.java
More file actions
40 lines (32 loc) · 1.05 KB
/
Copy pathShare.java
File metadata and controls
40 lines (32 loc) · 1.05 KB
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
/**
*
* Phonegap share plugin for Android
* Kevin Schaul 2011
*
*/
package com.schaul.plugins.share;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
public class Share extends Plugin {
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
JSONObject jo = args.getJSONObject(0);
doSendIntent(jo.getString("subject"), jo.getString("text"));
return new PluginResult(PluginResult.Status.OK);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
private void doSendIntent(String subject, String text) {
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
this.cordova.startActivityForResult(this, sendIntent, 0);
}
}