Android Read Result From MySQL - android

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)

Related

Reading Texts Kotlin - Android SDK 29

I'm relatively new to Android Dev and I'm running Android Studio on SDK 29 for a project to read through messages, find Roster text messages for where I work and then import them into the Google Calander via API. I've had a small amount of experience with Android before so the text and onClick etc are fine (Although I used java in the past, trying kotlin as it's the future). However I'm trying to play around with reading the body of all messages and just printing them to the screen so I can understand how it works, tweak things here and there and see the results I get. However just getting the body of messages and printing them is turning out to be quite difficult.
I had issues initially however they were to do with permissions not working correctly. From there I fixed that issue and got some working code with no errors however instead of getting an output of the body of the messages I got a random '12'. So after further researching and googling I've managed to get myself to what I think is a close lot of code however, it's just incomplete and I'm unable to see what errors there may be as I haven't found a working lot of code online yet.
Furthermore the android dev documentation hasn't been a huge help. So I'm reaching out. Sorry if this seems a easy fix however it's new to me and I havent' found anything online after a fair bit of searching.
Thanks in advance
This is my code so far:
var cr = contentResolver.query(
Uri.parse("content://sms/inbox"),
null,
null,
null,
null
)
if(cr.moveToFirst()){
do {
var msgData = ""
for(messages in cr.getColumnIndex("body")) {
lastSyncMessage.text =
lastSyncMessage.text.toString() + " " + msgData.toString()
}
}while(cr.moveToNext())
}
}```
Try the next code, the for loop is not correct:
if(cr!= null && cr.moveToFirst()){
do {
lastSyncMessage.text =cr.getString(cr.getColumnIndex("body"))
}while(cr.moveToNext())
}
This code will set the last sms body message as the lastSyncMessage text. Just play with this.

cordova.file.* (all directories) are null

I'm working on Ionic mobile app development.
My requirement is to create client side logger to track issues in app. I used the methods mentioned in https://github.com/pbakondy/filelogger, and I could able to create the log file in both Android and iOS.
For the first time when I open the app, it creates the log file in cordova.file.dataDirectory, when I close and reopen the app in i*OS, I'm trying to read the content of the file which was created using the below
$fileLogger.getLogfile().then(function (loggerContent) {
var temp =loggerContent;
});
But the application says
{
"applicationDirectory":null,
"applicationStorageDirectory":null,
"dataDirectory":null,
"cacheDirectory":null,
"externalApplicationStorageDirectory":null,
"externalDataDirectory":null,
"externalCacheDirectory":null,
"externalRootDirectory":null,
"tempDirectory":null,
"syncedDataDirectory":null,
"documentsDirectory":null,
"sharedDirectory":null
}
So I couldn't able to find the file where i saved my logs.
Please help me resolve this issue or if you could recommend me a different method to get around this issue, that would be great!
Thanks for the answers
There is a check list here and should solve your problem :
1-Be sure that the cordova-file-plugin is installed and works in your test environment.
2-Be sure that the cordova.js file is refrenced by your html and before your code usage.
3-Be sure to call your codes after device_ready state :
check this
4-Call your function after a short delay (use setTimeOut in Javascirpt)
Ali's item 4 is very important:
I had a similiar problem on different platforms: cordova.file.dataDirectory was null.
I tracked cordova.file.dataDirectory over the lifecycle and it was first accessed by my Ionic 2 code BEFORE the device ready event was fired.
My "mistake": I wanted to load data during the constructor(!) of a service. Seems too early.

Getting "You cannot access body after reading from request's data stream" while using django-rest-framework

My first question here, & a newbie to everything including coding.
I am using django-rest-framework to call a rest api from an android app I am building.
I am calling another view's method from the api_view method of django-rest-framework.
This works great with the GET method, but fails while using the POST method.
Below is the code:
View 1:
#api_view(['GET', 'POST'])
def get_dos(request):
return View2.get_data(request)
View 2:
def get_data(request):
#if I print request.body, it goes through without problems
#print request.body
#but commenting it fails when I read from request.POST.get below:
var1 = int(request.POST.get('test', 0))
#fails in the above statement.
I have tried commenting all middleware classes in the settings file, but no luck :(. I keep getting "You cannot access body after reading from request's data stream" error.
Am I doing something silly? Any assistance appreciated. Thanks!

error with pymtp to work on python 3

I want to access a android device from python to download some photos.
libmtp works from the CLI.
Than pymtp. It's been around for a while but it's designed for python 2 and i'm using python 3. Meanwhile fixed several minor issues but i'm stuck at an error from function get_filelisting
specially this section:
ret = []
next = files
while next:
ret.append(next.contents)
if (next(next.contents) is None):
break
next = next(next.contents)
The error is related to the "next".
That section looks strange to me, i've been coding in python for a while but i'm new to ctypes. Tried a lot of variants, they all failed. The "next" could be confusing with python buildin function so i renamed it to nextpointer and came to this code:
ret = []
nextpointer = files
while nextpointer:
ret.append(nextpointer.contents)
nextpointer = nextpointer.contents.next
It seems to work but did it work by accident ? does it have any design flaws ? Could anyone with experience on python ctypes confirm this a solution ? Any suggestion welcome.
From python2.7 documentation
next(iterator[, default])
Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is
exhausted, otherwise StopIteration is raised.
from python3 documentation
next(iterator[, default])
Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is
exhausted, otherwise StopIteration is raised.
Notice that next() method was removed from python3 but the function still exists.
This is all I can say about the next function and .next()/__next__() methods.
I downloaded the pymtp module and get_filelisting() is slightly different from what you posted in your ported code, here it is:
ret = []
next = files
while next:
ret.append(next.contents)
if (next.contents.next == None):
break
next = next.contents.next
If none of this helped you (which probably didn't :D), the version of pymtp library that I am using is 0.0.6 download using pip.

Jsoup and gzipped html content (Android)

I've been trying all day to make this thing works but it's still not right yet. I've checked so many posts around here and tested so many different implementations that I'dont know where to look now...
Here is my situation, I have a small php test file (gz.php) on my server wich looks like this :
header("Content-Encoding: gzip");
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$contents = gzcompress("Is it working?", 9);
print($contents);
This is the simplest I could do and it works fine with any web browser.
Now I have an Android activity using Jsoup that has this code :
URL url = new URL("http://myServerAdress.com/gz.php");
doc = Jsoup.parse(url, 1000);
Which cause an empty EOFException on the "Jsoup.parse" line.
I've read everywhere that Jsoup is supposed to parse gzipped content without having to do anything special, but obviously, there's something missing.
I've tried many other ways like using Jsoup.connect().get() or InpuStream, GZipInputStream and DataInpuStream. I did try the gzDeflate() and gzencode() methods from PHP as well but no luck either. I even tried not to declare the header-encoding in PHP and try to deflate the content later...but it was as clever as effective...
It has to be something "stupid" I'm missing but I just can't tell what... anybody has an idea?
(ps : I'm using Jsoup 1.7.0, so the latest one as of now)
The asker indicated in a comment that gzcompress was writing a CRC that was both incorrect and incomplete, according to information from here, the operative code being:
// Display the header of the gzip file
// Thanks ck#medienkombinat.de!
// Only display this once
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
// Figure out the size and CRC of the original for later
$Size = strlen($contents);
$Crc = crc32($contents);
// Compress the data
$contents = gzcompress($contents, 9);
// We can't just output it here, since the CRC is messed up.
// If I try to "echo $contents" at this point, the compressed
// data is sent, but not completely. There are four bytes at
// the end that are a CRC. Three are sent. The last one is
// left in limbo. Also, if we "echo $contents", then the next
// byte we echo will not be sent to the client. I am not sure
// if this is a bug in 4.0.2 or not, but the best way to avoid
// this is to put the correct CRC at the end of the compressed
// data. (The one generated by gzcompress looks WAY wrong.)
// This will stop Opera from crashing, gunzip will work, and
// other browsers won't keep loading indefinately.
//
// Strip off the old CRC (it's there, but it won't be displayed
// all the way -- very odd)
$contents = substr($contents, 0, strlen($contents) - 4);
// Show only the compressed data
echo $contents;
// Output the CRC, then the size of the original
gzip_PrintFourChars($Crc);
gzip_PrintFourChars($Size);
Jonathan Hedley commented, "jsoup just uses a normal Java GZIPInputStream to parse the gzip, so you'd hit that issue with any Java program." The EOFException is presumably due to the incomplete CRC.

Categories

Resources