I have 2 laptops. One is windows and one is Linux(Ubuntu). On the windows machine I'm unable to run android emulator app. I have tried with http://localhost/, http://10.0.2.2/ and none working. On Linux machine everything is work just fine. What can be the problem?
I have use Eclipse. And on machine localhost WAMP.
Update:
I have this code which I try to open via app. When I run it on my local i.e. http://localhost/file.php obviously I get this error for deprecated mysql_* function but the result is displayed (on the web host I don't get this errors). I've tried to turn of display_errors in php.ini and I notice that the app doesn't crash anymore and all is running. Is it really possible this to cause the problem?
<?php
$objConnect = mysql_connect("localhost","database","");
$objDB = mysql_select_db("tableName");
$strSQL = "SELECT * FROM res";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
Related
I'm new to Dart and Flutter. I know a bit about Sockets. Here is my question:
I tried to create a TCP socket on a emulator with flutter (on android emulator Pixel 3A API 33) and connect it with another emulator(identical but diffrent emulator, Pixel 3A API 33). I got en error it says "Connection Refused (OS Error: Connection refused, errno = 111),address = 0.0.0.0, port = 36802)
I'm trying to make p2p chat application using flutter. I'm creating a socket in here in p1:
myPort = 43761;
String mysocketIP = "0.0.0.0";
final Future<ServerSocket> mySocket = ServerSocket.bind(mysocketIP, myPort);
and listening the socket like this in p1:
mySocket.then((ServerSocket listenSocket) {
listenSocket.listen((Socket mysocket) {
mysocket.listen((Uint8List data) async {
String mysocketResponse = String.fromCharCodes(data);
String strData = utf8.decode(data);
if(mysocketResponse == "///initiate"){
p2pSocket.add(utf8.encode("Got you message"));
}
print(strData);
});
});
});
All code in p1 about socket is given.
And here comes p2, which is client. Trying to connect to p1:
(I'm getting relevant port and ip from a server. That part works fine, I tested. serverResponse is the response from server. recKey means reciever's key. Its not relevant to my problem. Just another stuff.
code comes to else if block and executes but in Socket.connect line it blows.
late String recieverClientIP;
late int recieverClientPORT;
/*
...
...
*/
else if(serverResponse.length>=8 && serverResponse.substring(0,8)=="//recKey") {
targetsKey = serverResponse.substring(8);
// p2p sohbeti baslatıyoruz.
p2pSocket = await Socket.connect(recieverClientIP, recieverClientPORT);
//p2pSocket.write("///initiate");
}
;
Here is the erros message I get:
ERROR MESSAGE
I realized that in error, it says another port number. I'm using (IP 0.0.0.0) port number 47761 in p1 and in error it says another port number. Maybe it about it? I don't know I'm so confused.
By the way I'm using Android Stuido. With Emulator. Emulator I'm using is Pixel 3A API 33 x86 64
EDÄ°T: I'm using 10.2.2.2 in Server, 0.0.0.0 in p1. I can not create a socket with 10.0.2.2 in p1 it gives error. That's why I'm using 0.0.0.0 it's working.
Thanks in advance.
I'm using this nu-get package to stream mp3 url in a Xamarin Android project:
https://github.com/martijn00/XamarinMediaManager
I followed the instructions in the link up there... and it shows the music playing in the notification bar but it is not working (no sound and it's not even starting the song).
Code snippet:
clickButton.Click += (sender, args) =>
{
ClickButtonEvent();
};
private static async void ClickButtonEvent()
{
await CrossMediaManager.Current.Play("http://www.montemagno.com/sample.mp3");
}
I built the sample included in the link, and I got the same result from their sample. Also deployed on real device too, same result!
Image:
Am I missing something ?
Or is the library broken ?
I ran into this using Android Emulator on Hyper-v. It turns out that the network is set to internal. So the http://www.montemagno.com/sample.mp3 could not be found. My workaround:
Hyper-v -> Virtual Switch Manager, add an external network.
Hyper-v -> Virtual Machines->Settings, add new hardware->Network adapter and set to external network.
"Visual Studio Emulator for Android" desktop app, launch phone vm,
in Visual Studio, deploy and run app.
Sound should work from external source now.
Permissions maybe? In the project site it states that for Android:
You must request AccessWifiState, Internet, MediaContentControl and
WakeLock permissions
By default example use ExoPlayerAudioService.
There are issue with url escape in ExoPlayerAudioService.GetSource method
private IMediaSource GetSource(string url)
{
string escapedUrl = Uri.EscapeDataString(url);
var uri = Android.Net.Uri.Parse(escapedUrl);
var factory = URLUtil.IsHttpUrl(escapedUrl) || URLUtil.IsHttpsUrl(escapedUrl) ? GetHttpFactory() : new FileDataSourceFactory();
var extractorFactory = new DefaultExtractorsFactory();
return new ExtractorMediaSource(uri
, factory
, extractorFactory, null, this);
}
string escapedUrl = Uri.EscapeDataString(url);
I.E. http://example.com/path_to_audio.mp3 will be escaped to "http%3A%2F%2Fexample.com%2Fpath_to_audio.mp3" as result HTTP error.
To fix just skip url escape.
My code used to work, it does not work anymore, I tried troubleshooting and can't figure out why.
I have this piece of code in my PHP:
$android_id_01 = $_GET['pmysql_room_id'];
$android_id_02 = "";
$f = fopen("00_android_id_01.txt", "w");
fwrite($f, print_r($android_id_01, true));
fclose($f);
$f = fopen("00_android_id_02.txt", "w");
fwrite($f, print_r($android_id_02, true));
fclose($f);
For troubleshooting I created two android IDs ($android_id_01 and $android_id_02) which are both empty (The first one is From Android and the second one I created directly from PHP).
Now when I launch my Android device, the PHP file is executed from server side and both the text files are created empty and identical. Now my code only works when I use $android_id_02 and not $android_id_01 from the code below:
if ($android_id == '')
{
//my code
}
(Yes when I use either one of the $android_id_01 OR $android_id_02 I rename it to $android_id and comment out the other one)
My question is, although this was working yesterday, why does it work with $android_id_02 = ""; and not $android_id_01 = $_GET['pmysql_room_id']; even though they are both empty????
I don't know what changed from yesterday to today.
Ok after a bit of troubleshooting I found a solution, strange though.
On the server side "display_errors" under PHP settings must be turned off. Somehow having this on interferes with the json_encode sent back to android client. (even though my code is not generating any errors)
I try to open a website in chrome and native android browser (emulated Android 5.0 and 6) to check several items.
every time i run the test, the choosen browser get started and in the url field stays 'data:,' btw the actual tab is also loaded two times.
I know there is a way to do this with selenium webdriver, but this is not the right way for me because i used the followed code for several emulated devices to test this website and on iOS/Mac osx its working.
So why not on android. My way to test this website is with capybara, appium and ruby.
on iOS there exists a
:safariInitialUrl =>'http://www.mypage.com'
cap.
but not for android.
So, my question is: how is it possible to start my website on an emulated android devices without using selenium webdriver.
code:
Capybara.register_driver :androidphone do |app|
capabilities = {
:deviceName => 'nex5_5',
:avd => 'nex5_5',
:browserName => 'Chrome',
:platformVersion => '5.0',
:platformName => 'Android',
:automationName => 'Appium',
}
url = "http://localhost:4723/wd/hub"
appium_lib_options = {
server_url: url
}
all_options = {
appium_lib: appium_lib_options,
caps: capabilities,
}
Appium::Capybara::Driver.new app, all_options
You have to add this line in your config file :
exports.config = {
directConnect:false,
}
I think you have also to add the Timeout in your configuration file, if you are using jasmine framework for example add this code :
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
I am doing python exercise with a book 'headfirst python'
and making android app by using python and sl4a
my code is
import android
import json
import time
from urllib import urlencode
from urllib2 import urlopen
hello_msg = "Welcome to Coach Kelly's Timing App"
list_title = 'Here is your list of athletes:'
quit_msg = "Quitting Coach Kelly's App."
web_server = 'http://127.0.0.1:8080'
get_names_cgi = '/cgi-bin/generate_name.py'
def send_to_server(url, post_data=None):
if post_data:
page = urlopen(url, urlencode(post_data))
else:
page = urlopen(url)
return(page.read().decode("utf8"))
app = android.Android()
def status_update(msg, how_long=2):
app.makeToast(msg)
time.sleep(how_long)
status_update(hello_msg)
athlete_names = sorted(json.loads(send_to_server(web_server + get_names_cgi)))
app.dialogCreateAlert(list_title)
app.dialogSetSingleChoiceItems(athlete_names)
app.dialogSetPositiveButtonText('Select')
app.dialogSetNegativeButtonText('Quit')
app.dialogShow()
resp = app.dialogGetResponse().result
status_update(quit_msg)
this is my code and the result is
what is the problem???
I can not figure out what the problem is...
Use 10.0.2.2:8080
because If you are running both server and emulator in you computer 127.0.0.1:(port) the local IP will refer to the emulator then you need another local IP for the server which will be automatically The 10.0.2.2
hope i clearified it well, glad i helped
Having followed #Coderji 's solution, I was finally able to solve this problem albeit with a different IP address; since the suggested 10.0.2.2 didn't work for me.
What worked for me was to access a terminal, ipconfig, and then used any of the provided ipv4 addresses provided by cmd (all of them seemed to work). Cheers.