So I'm trying to get a the URL being called into my app, but after it opens, it just always seems to be null not matter what I do.

Here's the relevant part of my manifest:

android:theme="@android:style/Theme.Black.NoTitleBar"

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"

android:launchMode="singleTask">

And here's my java:

@Override

public void onStart() {

super.onStart();

final Intent intent = getIntent();

Uri url = intent.getData();

Log.e("myLog", "Url = " + url);

}

The log is outputting "Intent = null", and I have no errors.

I'm not a java developer so I may have a simple problem I don't recognize. I'm going to pass this into my PhoneGap app with sendJavascript but being a PhoneGap app doesn't seem relevant to this issue.

EDIT:

I seem to only be getting the first when I log intent. Here's the log:

03-13 12:36:18.593: E/MyAppLog(13793): Intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.wd.myapp/.myapp (has extras) }

SOLUTION:

After pouring through dozens of posts on how to implement URL schemes to open your PhoneGap app, and none of them being very robust or working at all, I'm going to post my full solution and hope someone finds it useful.

Step one: AndroidManifest.xml - Add this to your , changing 'urlScheme' to whatever you like. In this case, you could click a link to urlScheme:///?key=val and it would open the app.

Step Two: myApp.java - Add the following underneath onCreate. If you are using singleTask, be sure to put your intent logic in the onStart function (instead of in onCreate, as others have trumpeted), as that will allow you to link into your app whether it's already running or not.

@Override

public void onStart() {

super.onStart();

final Intent intent = getIntent();

String url = intent.getDataString();

if(url != "" && url != null) {

super.sendJavascript("setTimeout(function() { handleOpenURL('" + url + "'); },1);");

}

}

@Override

protected void onNewIntent(Intent intent) {

super.onNewIntent(intent); setIntent(intent);

}

See the accepted answer for an explanation of the onNewIntent override.

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐