Reputation: 197
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
final String invokeString = getIntent().getDataString();
if(invokeString != "" && invokeString != null) {
this.sendJavascript("handleOpenURL('" + invokeString + "');");
System.out.println(invokeString);
}
}
I found this code on this website: http://blog.cttapp.com/p/phonegap-handleopenurl-for-android/.
It won't execute handleOpenURL, and I know this, because it would otherwise redirect the page.
Upvotes: 2
Views: 1544
Reputation: 318
I encountered the same problem and wanted to share a much worse (as far as I can tell) solution for anyone who might not want to build Cordova themselves...
Right before the line
this.sendJavascript("handleOpenURL('" + url + "');");
Add this
try{
Thread.sleep(5000);
} catch (Exception e) {
// nothing
}
I'm aware this isn't optimal but I really didn't have time to extend Cordova itself...
ALSO: since the link in the (much better) answer above is missing a little info (some forum messages in the solution thread have been deleted), here's the file whose onMessage you'll have to override...good luck!
Upvotes: 0
Reputation: 1505
I had the same problem. Seems like webview is not ready for it yet.
Here is how I got that to work: override the onMessage
function, because it seems to be ready to listen to you by then:
@Override
public Object onMessage(String id, Object obj) {
if (id.equals("onPageStarted")) {
final Intent intent = getIntent();
if(intent.getDataString()!= "" && intent.getDataString()!= null){
String url = intent.getDataString();
this.sendJavascript("handleOpenURL('" + url + "');");
}
}
return super.onMessage(id, obj);
}
I found this solution here.
Upvotes: 6