I am trying to code in C# with DOT42. How do I navigate to an html inside my Assets folder. I have achieved the same wit Eclipse in java with the following Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://www.google.com";
url="file:///android_asset/out/in/active_deals.html";
WebView webv = (WebView) findViewById(R.id.webview1);
WebSettings settings = webv.getSettings();
settings.setJavaScriptEnabled(true);
webv.setWebViewClient(new WebViewClient());
webv.loadUrl(url);
}
When I try to do the same in C# with DOT42, it says page not found:
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
string url = "";
//url = "http://www.google.com";
url = "file:///Android_Asset/out/in/active_deals.html";
WebView myWebView = (WebView)FindViewById(R.Ids.webview1);
myWebView.SetWebViewClient(new WebViewClient());
myWebView.LoadUrl(url);
WebSettings webSettings = myWebView.GetSettings();
webSettings.SetJavaScriptEnabled(true);
}
I have tried naming the assets folder in lower case and upper case, both don't seem to work.
I have tried 'Android_Asset','android_asset','Asset' but none of it worked. It works with eclipse though.
When you add an embedded resource to your Visual Studio project, it will be converted to an asset in your APK with the full namespace name.
For example take this URL:
var url = "file:///android_asset/dot42AssetWebView.Resources.Index.htm";
It works fine for an embedded resource named Index.htm in a namespace "dot42AssertWebView.Resources".
Related
When I build and run the application I see only black screen,The html file is using java script,video,audio file and images,I used these codes
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/aici/index.html");
}
I'm trying to make an app with a webview of facebook.com, i want to load custom css but i don't know how. I searched on Google but found old tutorials and i read that it has changed in Android Studio 2.0
Here is my code:
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.facebook.com/");
myWebView.setWebViewClient(new WebViewClient());
}
I built an android app that gives two choices, to open a special webpage inside a web view or through browser. The webpage containing java script and ajax, return a list of items.
There is no problem when the webpage is opened through browser but when trying to open the webpage through a webview, it return list of items but when I click on one of them it return an error message
an internal error has occurred
(TypeError) __gwt$exception:<skipped>:cannot call method 'setItem' of null
Here is my code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView web = (WebView)findViewById(R.id.webView);
Button browser = (Button)findViewById(R.id.Browser);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
web.setWebChromeClient(new WebChromeClient());
web.loadUrl("http://10.45.18.22:8080/feeds-portlet/List.jsp?a=xy#gmail.com");
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://10.45.18.22:8080/feeds-portlet/List.jsp?a=xy#gmail.com"));
browser.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
startActivity(i);
}
});
}
I have already enabled javascript in the webview !
I try to show local HTML in webview but it showing error.
Here's the source
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv= (WebView) findViewById(R.id.wv);
wv.getSettings().setPluginsEnabled(true); //error here
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
wv.loadUrl("file:///android_asset/index.html");
}
I hope someone can help me.
"This method was deprecated in API level 18. Plugins will not be supported in future, and should not be used."
see the question wich brings you the nswer : setPluginEnabled is undefined
I developed a game in HTML5. It contains JavaScript and HTML files. Now I want to add them to my Android app. How can I do this?
You need To add Webview to have HTML5 Files to be loaded this can be done like this
public class HelloWebView extends Activity {
WebView webview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new HelloWebViewClient());
webview.loadUrl("file:///android_asset/test.html");
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);
webview.setWebChromeClient(new WebChromeClient() {
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(5 * 1024 * 1024);
}
});
}
And place your HTML5 files inside assets.
Android Developer Website should be the first thing comes to mind. Check WebView Page.
For tutorial you can check :
http://www.mkyong.com/android/android-webview-example/
You can have webview within your android device which load the page that host your html5 game.