I'm just making a basic Webview app on an android emulator and cannot connect to a website hosted on my computer.
Here is my code:
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emswebviewer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
Main Activity Java file:
public class MainActivity extends Activity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.out.println("*** My thread is now configured to allow connection");
}
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("http://10.0.2.2:8080");
}
Terminal (Starting website on local host port 8080):
Michaels-MacBook-Pro-5:web michael$ php -S localhost:8080
PHP 5.5.14 Development Server started at Mon Dec 22 14:08:01 2014
Listening on http://localhost:8080
httpd.conf File (Under Apache Folder):
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Applications/MAMP/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options All
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
I am using Mamp and AVD as the emulator.
When I run my app, it returns net::ERR_CONNECTION_REFUSED on the Main activity page.
Do I need to allow external connections somewhere? OR is there something inherently wrong with what I am trying to do?
localhost on your emulator it's not localhost on your desktop. On your desktop you need to run php server with php -S 10.0.2.2:8080 (if that it's your IP). And than access that IP from the emulator with WebView at your app. You can't access desktop's localhost from the emulator (no directly at least). Don't start your server on localhost only.
Look for this file ports.conf and add Listen 8080 if necessary and restart the server.
Using 10.0.2.2 is correct and not wrong in anyway as such. You can see why in the below answer
why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client
The issue may be related to your application listening to 127.0.0.1 only and not all interfaces. You need to make sure you use something like below
php -S 0.0.0.0:8080
I saw your bounty question as well, which also answers that you need run your Django server as below
python manage.py runserver 0.0.0.0:8000
PS: And next time your post a bounty #kingraphaII, be kind enough to respond to people and don't just be a ghost
What worked for me was to replace localhost address with my pc laptop, 192.168.2.7, in my case. #gorlok comment helped me towards my solution.
Android Emulator is a separate device. Emulator isn't part You Computer. Emulator cann't access your Local Server.
So Emulator return net::ERR_CONNECTION_REFUSED error.
I found a Simpal way to solve the issue.
Get my local IP address as like 192.168.99.112
To get your IP address open your Tarminal/cmd type ipconfig
Ensure your internet permission in AndroidManifest File
<uses-permission android:name="android.permission.INTERNET"/>
Then
WebView browser = (WebView)findViewById(R.id.webview);
webView.loadUrl("http://192.168.99.112/projectName");
Related
I have a laravel project contains an RestFull API. I want to access to this API from android studio. I use retrofit library.When I run server through artisan, can't access localhost laravel app routes to android studio.According to this question accessing-localhost-laravel-app-routes-to-android-studio-failed, I change base url to http://192.168.1.103:8000/halamooz/public/api/ and run the laravel app with apache server.For this work, I follow this guideline Laravel practical guide for using XAMPP.Of course I don't use XAMPP and install apache server individually. I access web route from browser but when I try to access API route from postman or android studio I receive 404 page not founded error.What is my mistake?
I put this lines in httpd-vhosts file:
<VirtualHost *:80>
DocumentRoot "C:/apache/htdocs/halamooz/public"
ServerName exampledomain.com
ServerAlias exampledomain.com
<Directory "C:/apache/htdocs/halamooz/public">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
In httpd.conf file find
Listen 80
and below that write
Listen 8060
Then goto httpd-vhosts.conf
<VirtualHost *:8060>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/apache/htdocs/halamooz/public"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Replace DocumentRoot with your path of project. Hope this help you
I finally did these steps and My problem solved.
Step 1:
Put your laravel project into C:\apache\htdocs.
Step 2: Run as administrator notepad app and open hosts file from C:\Windows\System32\drivers\etc path and add this line to end of file.
127.0.0.1 exampledomain.com www.exampledomain.com
Step 3: Open httpd-vhosts file from C:\apache\conf\extra path and add these lines to end of file:
<VirtualHost *:80>
DocumentRoot "C:/apache/htdocs/NameOfProject/public"
ServerName exampledomain.com
ServerAlias exampledomain.com
<Directory "C:/apache/htdocs/NameOfProject/public">
AllowOverride All
Require all Granted
Step 4:Uncomment this line from C:\apache\conf\httpd.conf file.
Include conf/extra/httpd-vhosts.conf
Step 5:Use this Url to access API in postman or android studio project.
http://{IPv4 of your computer}:8000/{ProjectName}/public/api/{desired method}
For example:
http://192.168.1.3:8000/halamooz/public/api/login
Notice: Your Android device and computer must be on a same network Internet.
Im trying to copy some files to and from a windows share. I am using python 2.7 and the pysmb library. This works fine with win7, but not with android. I build my connection over VPN with SMBConnection. listShares and listPath is working. Under win7 there is no problem using also os.path.isdir or shutil.copyfile. But that does not work with android. This is my code:
server_name = '192.168.168.12'
conn = SMBConnection(username=username, password=password, my_name='waldi2'
remote_name=server_name, domain=domain, use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED, is_direct_tcp=True)
connected = conn.connect(server_name, 445)
# obtain a list of shares:
Response = conn.listShares(timeout=30) # !!!working, shows e.g.(' Share[', 20, '] =', u'JBW_in')
os.path.isdir('//192.168.168.12/JBW_in/') # is False with android, True with win7 !??
shutil.copyfile('/sdcard/waldi2_0/data/stop.txt', '//192.168.168.12/JBW_in/stop.txt')
This is no prob with win7, but with android it throws:
[Errno 2] No such file or directory: '//192.168.168.12/JBW_in/stop.txt'
Any clues? would be very very welcome ....
Or maybe alternative approaches to manage some python-based file-exchange between android and windows-server.
If I understund you correctly you are trying to connect to an android device via SMB. By my knowledge android doesnt have support for SMB server natively, but you could install a third-party app with a SMB server.
I have just bought a Positive SSL Certificate but it does not work in Chrome for Android, I get NET::ERR_CERT_AUTHORITY_INVALID. However, everything is OK with the Chrome for desktop.
This is how I configure my apache2 server:
# File /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName example.com
SSLEngine on
SSLCertificateFile /root/ssl/certificate/example.com.crt
SSLCertificateKeyFile /root/ssl/example.com.key
SSLCertificateChainFile /root/ssl/certificate/intermediates.crt
# In version 2.4.8 or newer
#SSLCACertificateFile /root/ssl/certificate/intermediates.crt
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And here it's how I created intermediates.crt:
cat COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt > intermediates.crt
What am I missing?
I thought the intermediates were wrong, but taking a closer look at the Comodo website, your configuration appears to be correct -- the right certificates in the right order.
Have you tried running your site through the SSL Labs Server Test?
After trying almost every combination, I found the solution. I had to create the bundle using all the files: my certificate, the two intermediates and the root.
cat example.com.crt \
COMODORSADomainValidationSecureServerCA.crt \
COMODORSAAddTrustCA.crt \
AddTrustExternalCARoot.crt > intermediates.crt
With Dynamic Debugging enabled in the Linux Kernel, I am able to control which prints show up by writing to /sys/kernel/debug/dynamic_debug/control. However, It seems that a reboot resets this file to its default settings (all prints disabled).
Is there a way to make the settings persist across a reset? I have a print which is emitted early in the boot process, and I am not able to get it to print, because the reboot disables this print in /sys/kernel/debug/dynamic_debug/control.
You should be able to add dyndbg='your query here' to the kernel command line using the bootloader configuration or manual options entry feature. This will vary with the bootloader although grub is the most common one
If you are using grub as a bootloader you would have to add it to the kernel command line in /boot/grub/grub.conf for the particular kernel you are launching at bootup.
A blog article about this can be found here. In particular it gives this example:
dyndbg='module xhci_hcd +p'
The article also discusses modifying grub as well.
This kernel howto about dynamic debugging has useful information about dyndbg. This section applies
To activate debug messages for core code and built-in modules during
the boot process, even before userspace and debugfs exists, use
dyndbg="QUERY", module.dyndbg="QUERY", or ddebug_query="QUERY"
(ddebug_query is obsoleted by dyndbg, and deprecated). QUERY follows
the syntax described above, but must not exceed 1023 characters. Your
bootloader may impose lower limits.
These dyndbg params are processed just after the ddebug tables are
processed, as part of the arch_initcall. Thus you can enable debug
messages in all code run after this arch_initcall via this boot
parameter.
On an x86 system for example ACPI enablement is a subsys_initcall and
dyndbg="file ec.c +p"
will show early Embedded Controller transactions during ACPI setup if
your machine (typically a laptop) has an Embedded Controller.
PCI (or other devices) initialization also is a hot candidate for using
this boot parameter for debugging purposes.
If foo module is not built-in, foo.dyndbg will still be processed at
boot time, without effect, but will be reprocessed when module is
loaded later. dyndbg_query= and bare dyndbg= are only processed at
boot.
You can do it as a part of post boot script. Say after Android boots(since i see Android tag added here), it runs certain sh scripts as a part of init procedure. Modify the sh files with the dynamic debug commands added and push it in and reboot .
Refer here for post boot script files info.
https://android.stackexchange.com/questions/6558/how-can-i-run-a-script-on-boot
You can have dynamic_debug for some kernel module foo activated automatically during boot using the /etc/modprobe.d/ directory.
### BEGIN prerequisite
# in case module "foo" is not yet automatically loaded during boot,
# then make it load during boot:
# create a file /etc/modules-load.d/foo.conf with contents "foo"
echo "foo" | sudo tee /etc/modules-load.d/foo.conf
### END prerequisite
# create a configuration file to activate dynamic debug for module "foo"
# at its "module initialization time"
echo "options foo dyndbg=+p" | sudo tee /etc/modprobe.d/foo.conf
Reference: Debug Messages at Module Initialization Time from kernel.org documentation.
I have an apache server installed in my PC where I host one PHP file.
Then I tried to connect to that file using eclipse, but it always gives me below error
connection to http://10.0.2.2:8080 refused.
I tried changing address to the followings, but got similar error all the time.
http://10.0.2.2
http://127.0.0.1
http://localhost
Can anyone please help me.
EDITED: Just for information, I can access to remoter server (e.g. www.mydomain.com) without any problem.
CLASS FILE:
HttpClient httpclient = new DefaultHttpClient();
Log.d("test","t0");
HttpPost httppost = new HttpPost("http://10.0.2.2:8080/mylibman/data.php");
Log.d("test","t1");
HttpResponse response = httpclient.execute(httppost); // error here
Log.d("test","t2");
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.migrationdesk.mylibman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
Error LogCat:
11-16 02:02:20.803: E/log_tag(1427): Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
11-16 02:02:20.803: E/log_tag(1427): Error converting result java.lang.NullPointerException: lock == null
11-16 02:02:20.803: E/log_tag(1427): Error parsing data org.json.JSONException: End of input at character 0 of
alright go to Apache httpd.conf (located in Apache folder): and search for
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
and check if the second line is Deny, if it is then change it to:
Allow from all
then restart the Appache server, and tell me the feadback.
Edit
try it out in your real device:
go to CMD and type ipconfig under IPv4 take the IP address and change the IP it will look similar to this:
http://192.168.0.106:8080/mylibman/data.php // similar to this.
Turn Off the firewall and any anti-virus application in your PC
and please give me the feedback.
Mike helped me a lot on this issue. So here my steps to avoid this Connection refused.
1) Add if to test Android SDK. It seems that in new versions you have to explicity allow the connection to be open in a different thread:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.out.println("*** My thread is now configured to allow connection");
}
...
2) Add an exception for your port:
in your case allow inbound connection for port 8080
3) test your connection by browsing the desired url locally
use your browser and try to visit http://10.0.2.2:8080 locally
4) Add in your manifest file a permission for internet:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourapp"
android:versionCode="1"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
I am using Wamp, and its apache is listening to servername localhost and port 8080 (allow from all in httpd.conf).
My local IP is something similar to 192.168.0.XXX/folder/my-page-here
You can use your real IP address to reach your virtual server. Take a look at my answer here. I hope it helps.
if your SDK version is less then 9 then add above code for SDK version them some changes in Apache update httpd.conf as line deny from all..replace that sentence Allow from all and restart services of WAMP server then use 10.0.2.2 address or 10.0.2.2:8080 port no and include permission line in android AndroidManifest file
<uses-permission
android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
I fix this problem by writing my IP address from cmd -> ipconfig in the url :
HttpPost httppost = new HttpPost( "http://192.168.x.x/mylibman/data.php" );