Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

android - Need to call an activity back from javascript interface made for WebView

I am working on an application which uses web view in one of it's activities. I have attached a java script interface with the web content. I need to call an activity with data in bundle based on the click event(can say touch event). I can pass data back to Java script interface but it's not letting me call startActivity(Intent). Is there any other way I can call an activity. Thanks in advance!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here are the things that you need to do to support this :

  1. For the activity to be launched : Handle the android.intent.category.BROWSABLE category with the a particular scheme.

  2. In WebView onClick, load the url starting with scheme handled by the app.

For ex : TestActivity

<manifest>
 <application>
   <activity>
    <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="test-app"/>
     </intent-filter>
   </activity>
 </application>
</manifest>

URL to load after web view click :

webView.loadUrl( "test-app://data-that-you-want-to-transfer" );

HTH !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...