Permalink
Browse files

Added onNewIntent and getUri for WebIntent plugin

  • Loading branch information...
1 parent 9ebabdb commit e50700dbb2f531d57509874634dd1f2b0cbfa71e @yuvipanda yuvipanda committed Jan 24, 2012
Showing with 66 additions and 5 deletions.
  1. +21 −3 Android/WebIntent/README.md
  2. +28 −0 Android/WebIntent/WebIntent.java
  3. +17 −2 Android/WebIntent/webintent.js
@@ -6,7 +6,7 @@ By Boris Smus
2. Create a folder called "borismus" within your project's src/com/ folder and move the java file into it.
## Using the plugin ##
-The plugin creates the object `window.plugins.webintent` with three methods:
+The plugin creates the object `window.plugins.webintent` with five methods:
### startActivity ###
Launches an Android intent. For example:
@@ -41,7 +41,25 @@ Gets the extra that this app was invoked with. For example:
// There was no extra supplied.
}
);
-
+
+### getUri ###
+Gets the Uri the app was invoked with. For example:
+
+ window.plugins.webintent.getUri(function(url) {
+ if(url !== "") {
+ // url is the url the intent was launched with
+ }
+ });
+
+### onNewIntent ###
+Gets called when onNewIntent is called for the parent activity. Used in only certain launchModes. For example:
+
+ window.plugins.webintent.onNewIntent(function(url) {
+ if(url !== "") {
+ // url is the url that was passed to onNewIntent
+ }
+ });
+
## Licence ##
The MIT License
@@ -64,4 +82,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE.
@@ -9,6 +9,7 @@
import android.content.Intent;
import android.net.Uri;
+import android.util.Log;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
@@ -25,6 +26,7 @@
*/
public class WebIntent extends Plugin {
+ private String onNewIntentCallback = null;
/**
* Executes the request and returns PluginResult.
*
@@ -79,6 +81,23 @@ public PluginResult execute(String action, JSONArray args, String callbackId) {
} else {
return new PluginResult(PluginResult.Status.ERROR);
}
+ } else if (action.equals("getUri")) {
+ if (args.length() != 0) {
+ return new PluginResult(PluginResult.Status.INVALID_ACTION);
+ }
+
+ Intent i = this.ctx.getIntent();
+ String uri = i.getDataString();
+ return new PluginResult(PluginResult.Status.OK, uri);
+ } else if (action.equals("onNewIntent")) {
+ if (args.length() != 0) {
+ return new PluginResult(PluginResult.Status.INVALID_ACTION);
+ }
+
+ this.onNewIntentCallback = callbackId;
+ PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
+ result.setKeepCallback(true);
+ return result;
}
return new PluginResult(PluginResult.Status.INVALID_ACTION);
} catch (JSONException e) {
@@ -87,6 +106,15 @@ public PluginResult execute(String action, JSONArray args, String callbackId) {
}
}
+ @Override
+ public void onNewIntent(Intent intent) {
+ if (this.onNewIntentCallback != null) {
+ PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
+ result.setKeepCallback(true);
+ this.success(result, this.onNewIntentCallback);
+ }
+ }
+
void startActivity(String action, Uri uri, String type, Map<String, String> extras) {
Intent i = (uri != null ? new Intent(action, uri) : new Intent(action));
if (type != null) {
@@ -28,6 +28,14 @@ WebIntent.prototype.hasExtra = function(params, success, fail) {
}, 'WebIntent', 'hasExtra', [params]);
};
+WebIntent.prototype.getUri = function(success, fail) {
+ return PhoneGap.exec(function(args) {
+ success(args);
+ }, function(args) {
+ fail(args);
+ }, 'WebIntent', 'getUri', []);
+};
+
WebIntent.prototype.getExtra = function(params, success, fail) {
return PhoneGap.exec(function(args) {
success(args);
@@ -36,7 +44,14 @@ WebIntent.prototype.getExtra = function(params, success, fail) {
}, 'WebIntent', 'getExtra', [params]);
};
+
+WebIntent.prototype.onNewIntent = function(callback) {
+ return PhoneGap.exec(function(args) {
+ callback(args);
+ }, function(args) {
+ }, 'WebIntent', 'onNewIntent', []);
+};
+
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('webintent', new WebIntent());
- PluginManager.addService("WebIntent","com.borismus.webintent.WebIntent");
-});
+});

0 comments on commit e50700d

Please sign in to comment.