• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android App Development Help

So i would like to have one button on my app (just simple) and when i click it it sends a page like 192.168.1.195 that is hosted on a arduino so i can remotely turn a led on and off. How would i do this and where would the code go?

Thanks!
 
I don't want to use Bluetooth I just want to know how to display a webpage, i have already done the arduino code with ethernet
 
I HAVE THE ARDUINO CODE i just want to know how to display the webpage that the arduino is hosting!

Right. First thing is kid, don't shout at people on forums when they are trying to help you. People here who try to help give their time freely, and I don't appreciate being shouted at. In fact I'm the only here who does offer any help, so you really don't want to annoy me.

So, now we're getting a clearer picture of what you're trying to do, there are a couple of ways you can display a webpage on your Android device:-

1. Use the web browser. The simplest solution, as you don't need to write any code at all.
2. If you wish to write an app to display the web page, use a Webview component. Here's a link to a tutorial:

https://www.tutorialspoint.com/android/android_webview_layout.htm

Rather than regurgitate all that information here, I'll let you absorb that, try it out. If you have any further problems, come back here and ask questions.
 
So i started to play around with the code and i got this for the xml:

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

This for java:

package com.mikeashwell.androidled;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private class MyBrowser extends WebViewClient {
@override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}

And this for manifest:

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

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:roundIcon="@Mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@Style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

But when i look at the java, the webviewclient, webview and loadurl all come up red saying the symbol cannot be resolved.

What is this, please help me!
 
To start with, you're missing the required import statements in your code

Code:
import android.webkit.WebView;
import android.webkit.WebViewClient;
 
You don't create an instance of your WebViewClient. And so there is no code which loads the URL into the WebViewClient.
Please go back and re-read the tutorial example. Try to understand what it's doing, rather than blindly pasting code fragments.
 
You don't create an instance of your WebViewClient. And so there is no code which loads the URL into the WebViewClient.
Please go back and re-read the tutorial example. Try to understand what it's doing, rather than blindly pasting code fragments.

Update java:

package com.mikeashwell.androidled;

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

public class MainActivity extends AppCompatActivity {

private WebView wv1;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wv1=(WebView)findViewById(R.id.webview);
wv1.setWebViewClient(new MyBrowser());
}

private class MyBrowser extends WebViewClient {
@override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
 
Last edited:
Oh i need to put a text field and then thats part is in the website you gave me. Oh......i dumb


UPDATE:

I have got it working java:

package com.mikeashwell.androidled;
import android.app.Activity;
import android.os.Bundle;

import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;


public class MainActivity extends Activity {
Button b1;
EditText ed1;

private WebView wv1;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1=(Button)findViewById(R.id.button);
ed1=(EditText)findViewById(R.id.editText);

wv1=(WebView)findViewById(R.id.webView);
wv1.setWebViewClient(new MyBrowser());

b1.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
String url = ed1.getText().toString();

wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.loadUrl(url);
}
});
}

private class MyBrowser extends WebViewClient {
@override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}

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=".MainActivity">

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter Text"
android:focusable="true"
android:textColorHighlight="#ff7eff15"
android:textColorHint="#ffff25e6"
android:layout_alignBottom="@+id/button"
android:layout_alignParentStart="true" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter"
android:id="@+id/button"
android:layout_toRightOf="@+id/imageView"
android:layout_alignParentEnd="true"
android:layout_below="@+id/imageView" />

<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText"
android:layout_alignParentEnd="true" />

</RelativeLayout>

manifest:

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

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:theme="@Style/AppTheme" >

<activity
android:name=".MainActivity"
android:label="@String/app_name" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

</application>
</manifest>

But now how would i export it to a apk
 
Last edited:
Back
Top Bottom