我们为java活动做的方式是使用Intent的额外功能. Android上的java Activity和AIR app是什么参数传递机制.目前我们通过共享一个公共位置(sqlite db)并每秒轮询它来传递参数.这不是一个好的设计,我相信必须有一些好的方法来做到这一点.请赐教.
解决方法
By using this feature an application can be made invokable from browser or native android application. When the application is invoked from browser/android-app,an
InvokeEvent
is dispatched to the application.
For making an application invokable from browser,add this in your application descriptor (as child of application element):
- <android>
- <manifestAdditions>
- <![CDATA[
- <manifest>
- <application>
- <activity>
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.VIEW"/>
- <category android:name="android.intent.category.BROWSABLE"/>
- <category android:name="android.intent.category.DEFAULT"/>
- <data android:scheme="testapp"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
- ]]>
- </manifestAdditions>
- </android>
Now to launch your application from browser,provide the url as:
testapp://
. An example is:
- <a href="testapp://">click here to launch air test app from browser</a>
Clicking on this link will launch your application.
If you want to pass additional arguments to your application from browser,use something like this:
- <a href="testapp://arg1=value&secondArgument=someValue">click here to launch air test app from browser</a>
Once your application gets launched,fetch the arguments property of received
InvokeEvent
. This will contain the complete URI (testapp://arg1=value&secondArgument=someValue
) and you can parse it to extract the arguments.
从here起.