A common trick in mobile application development, is communication between two unrelated applications. In Android we have intents which are pretty elaborate and can be used via Display.execute, however what if you would like to expose the functionality of your application to a different application running on the device. This would allow that application to launch your application.
This isn't something we builtin to Codename One, however we did expose enough of the platform capabilities to enable that functionality rather easily on Android.
On Android we need to define an intent filter which we can do using the android.xintent_filter build argument, this accepts the XML to filter whether a request is relevant to our application:
android.xintent_filter=<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter>
This is taken from this stack overflow question, to bind the myapp:// URL to your application. So if you will type myapp://x into the Android browser your application will launch.
So how do you get the "launch arguments", passed to your application?
Display.getInstance().getProperty("AppArg") should contain the value of the URL that launched the app or would be null if it was launched via the icon.
iOS is practically identical with some small caveats, iOS's equivalent of the manifest is the plist. So we allow injecting more data into the plist thru the
ios.plistInject build argument.
So the equivalent in the iOS side would be ios.plistInject=<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.yourcompany.myapp</string> </dict> <dict> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
On a separate unrelated note the guys from Java Code Geeks announced the winners of our raffle of two tickets, yesterday. Congratulations to both winners!