2015-10-22 66 views
4

我需要在我的應用程序中調用一個網站,該網站無法通過與android一起提供的原生web視圖正確顯示。Android WebView的替代

我已經在網上搜索了一些答案,但是我在這個Is there an alternative to webview?旁找到了很多。

正如在上面的帖子中所建議的,我已經測試了人行橫道。然而,人行橫道有很多缺點:

  1. 極不穩定和不完整的
  2. 路太大(包括人行橫道將炸燬你至少50 MB的APK)
  3. 恕我直言,不是生產做好準備。

所以,我其實非常拼命尋找替代品,但找不到任何。

有沒有人知道工作和生產就緒的webview?這會幫助我太多。

編輯:

我不得不添加webView.getSettings().setDomStorageEnabled(true);,使網站的工作。

+0

WebView對於我認爲的應用程序來說是足夠的。你面臨哪些問題?您的網站是否兼容? –

+1

你會同意,在目前的形式下,這個問題是脫離主題(要求非現場資源)。如果你能解釋你的問題的確切性質...... – e4c5

+0

看看新的[Chrome自定義標籤](http://android-developers.blogspot.in/2015/09/chrome-custom-tabs-smooth-transition.html )&[source](https://github.com/GoogleChrome/custom-tabs-client) – pRaNaY

回答

2

適用於Android應用程序開發人員的新的Chrome custom tabs

通過在Android的WebView之上構建自定義瀏覽體驗,您可以獲得更精細的控制權,但代價是更復雜的技術和不熟悉的用戶瀏覽體驗。最新版本的Chrome中的一項新功能稱爲自定義標籤通過允許應用定製Chrome外觀和感覺的方式解決了這個折衷問題,從而使從應用程序到網頁內容的轉換更加快速和無縫。

查找Chrome的自定義選項卡谷歌代碼示例是here

爲了實現: -

請檢查Implementation guide for Chrome custom tabs

enter image description here

2

自定義選項卡是一作爲@pRaNaY的方式提及。這裏是一個快速的實現:

private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR"; 
    private static final String PACKAGE_NAME = "com.android.chrome"; 
    private CustomTabsClient mClient; 


@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     warmUpChrome(); 
     launchUrl(); 
    } 

    private void warmUpChrome() { 
     CustomTabsServiceConnection service = new CustomTabsServiceConnection() { 
      @Override 
      public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {    
       mClient = client; 
       mClient.warmup(0); 
      } 

      @Override 
      public void onServiceDisconnected(ComponentName name) {    
       mClient = null; 
      } 
     }; 

     CustomTabsClient.bindCustomTabsService(getApplicationContext(),PACKAGE_NAME, service); 
    } 

private void launchUrl() { 
     Uri uri = getIntent().getData(); 
     if (uri == null) { 
      return; 
     } 
     CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build(); 
     customTabsIntent.intent.setData(uri); 
     customTabsIntent.intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, getResources().getColor(R.color.red)); 


     PackageManager packageManager = getPackageManager(); 
     List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY); 

     for (ResolveInfo resolveInfo : resolveInfoList) { 
      String packageName = resolveInfo.activityInfo.packageName; 
      if (TextUtils.equals(packageName, PACKAGE_NAME)) 
       customTabsIntent.intent.setPackage(PACKAGE_NAME); 
     } 

     customTabsIntent.launchUrl(this, uri); 
    } 

搖籃:

compile "com.android.support:customtabs:23.0.0" 

其他注意事項:

調用warmUpChrome儘早將切換到瀏覽器速度更快。該示例中的實現適用於深層鏈接,但如果要手動啓動它,請重寫launchUrl並提供URI或String作爲參數。這些代碼大部分是從其他的stackoverflow答案縫合在一起的,但我已經改變了它的一些部分以適合我的情況。