本文介绍: 首先,要给你要打开应用中的activity设置过滤器,一般是启动activity。&lt;activity android:name=”.JumpActivity” &gt; <intentfilter> <action android:name=”android.intent.action.VIEW” /> <category android:name=”android.intent.category.DEFAULT” />

首先,要给你要打开应用中的activity设置过滤器,一般是启动activity。

<activity android:name=".JumpActivity" >  
  <intent-filter>  
    <action android:name="android.intent.action.VIEW" />  
    <category android:name="android.intent.category.DEFAULT" />  
    <category android:name="android.intent.category.BROWSABLE" />  
		<!--下面所设置的质需要html端对调-->
		<!--在data设置schemehost,则该Activity可以接收处理类似于 "sharetest://data/XXX"的链接-->
    <data  
      android:host="data"  
      android:scheme="sharetest" />  
  </intent-filter>  
</activity>

然后,在JumpActivity中做打开后的处理,用来接收外部的跳转

作者编程小石头
链接https://zhuanlan.zhihu.com/p/62840092
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

public class JumpActivity extends Activity{  
  @Override  
  protected void onCreate(Bundle savedInstanceState) {  
    // TODO Auto-generated method stub  
    super.onCreate(savedInstanceState);  
		
    Intent intent = getIntent(); 
    String data = intent.getDataString(); 
    String[] split = data.split("data/"); 
    url = split[1];  
   //然后我们通过网页打开app的同时就可以用获得的url数据做一些我们需要做的处理
	//	比如你在微信里浏览网页打开自己安卓app应用的同时,加载一个app内的网页
  }  
    
}

然后新建一个index.html

<!DOCTYPE html>  
	<html>  
	<body>  
	<iframe src="sharetest://data/http://www.huxiu.com/" style="display:none"></iframe>  
	</body>  
	</html>

下面是一段测试代码

public class H5ToAppActivity extends Activity {
  private String url;
  private WebView webview;
 
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_h5_app);
 
 
    webview = (WebView) findViewById(R.id.webviewh5);
    url = "file:///android_asset/index.html";
 
 
    WebSettings wSet = webview.getSettings();
    wSet.setJavaScriptEnabled(true);
    webview.loadUrl(url);
  }
}

原文地址:https://blog.csdn.net/xiangzhihong8/article/details/124627843

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_16869.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注