Skip to content

Commit

Permalink
Added onNewIntent and getUri for WebIntent plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Jan 24, 2012
1 parent 9ebabdb commit e50700d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
24 changes: 21 additions & 3 deletions Android/WebIntent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
28 changes: 28 additions & 0 deletions Android/WebIntent/WebIntent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@
*/
public class WebIntent extends Plugin {

private String onNewIntentCallback = null;
/**
* Executes the request and returns PluginResult.
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions Android/WebIntent/webintent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.