Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Framework7 inside webview pages not loading

I am new to framework7 and I am trying to make it work inside on android.

Here's what I did, Created project in android studio, with webview to load index.html and it works. But the link to the pages "about", "services" and "form" doesn't work.

I saw that framework7 uses ajax to call those pages.

So I think it doesn't work in webview that way correct?

Do I need to change the way framework7 initializes to load pages using javascript or what?

It is possible to make it work that way? Load the contents of another html file as page and not using "inline" pages?

Some advice?

Update with my code (using android studio):

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="atlasdb.atlasdatabase.MainActivity">

    <WebView
        android:id="@+id/atlasdatabase"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

MainActivity.java:

package app.apptest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView myWebView = (WebView) findViewById(R.id.apptest);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setAppCacheEnabled(true);
        webSettings.setDatabaseEnabled(true);
        myWebView.loadUrl("file:///android_asset/index.html");

    }
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="app.apptest">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
like image 293
RogerHN Avatar asked Aug 25 '16 14:08

RogerHN


1 Answers

Allow file access to your webview by adding these lines to webSettings:

webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);

Example project:

Andorid-Framework7-StartKit at Github

like image 161
David Antoon Avatar answered Oct 20 '22 22:10

David Antoon