URL and Link repository

Tuesday, February 20, 2018

Android: HttpURLConnection java.io.FileNotFoundException

This is a nasty little error that I was seeing in the Log Cat while debugging my Android app.
I was using
//letterStrings is an ArrayList() populated with 'aaa','bbb','ccc','ddd'
JSONArray jsonArray = new JSONArray(letterStrings);
//jsonArray looks like this: ['aaa','bbb','ccc','ddd'];
sNotes = 'These are my notes';
URL url = null;
HttpURLConnection urlConnection = null;
String link = "http://somewebsite.com?&userID=3&jsonArray="+jsonArray+"¬es="+sNotes;
// The above looks like this when resolved: "http://somewebsite.com?&userID=3&jsonArray=['aaa','bbb','ccc','ddd']¬es=These are my notes";
url = new URL(link);
urlConnection = (HttpURLConnection) url.openConnection();
Funny thing is that the resolved string link runs just fine from the browser address bar.
From within Android using HttpURLConnection, the link results in a FileNotFoundException.
Why? You ask.
Because I must make sure that the values for jsonArray and sNotes are properly formatted for the URLconnection.
Therefore, I must first do the following before I put together the string link.
String urlNotes = URLEncoder.encode(snotes, "UTF-8");
String urlJson = URLEncoder.encode(jsonArray.toString(), "UTF-8");
Now the String link = "http://somewebsite.com?&userID=3&jsonArray="+urlJson+"¬es="+urlNotes;

Android Overlay a First Run Tutorial screen over the Main Activity

Here is a great link on how to create the overlay. Christian Peters

Tuesday, December 5, 2017

Inserting Dates and Times from Visual Basic Web Form to MySQL Database

Not pretty but it resolves that invalid string error.

ASP code / mark up:
<asp:TextBox> TextMode='Date' ID='StartDateBox' runat='server'</asp:TextBox>
<asp:TextBox> TextMode='Time' ID='StartTimeBox'runat='server'</asp:TextBox>
Visual Basic server code:
Dim sTime As DateTime = Convert.ToDateTime(StartTimeBox.Text.toString) 
Dim insertstring as String='INSERT INTO [sometable] (Start_Date, Start_Time) values (@sd, @st)'
Dim mySqlcmnd = New MySqlCommand(insertstring, [your db connection])
mySqlcmnd.Parameters.AddWithValue('sd', StartDateBox.Text)
' 24 hour format
mySqlcmnd.Parameters.AddWithValue('st', sTime.ToString("HH:mm"))
Dim rowCnt as Integer = mySqlcmnd.ExecuteNonQuery

Sunday, November 5, 2017

Android to PHP Calendar Week View

I need to display a week of data between the Sunday and Saturday that surround a given date.


SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//current date on mobile
String formattedDate = df.format(Calendar.getInstance().getTime());
//format the get
String url = HOME_PAGE+"/mobile/getsessions.php?sessDate="+formattedDate";


$sessDate=mysqli_real_escape_string($dbconn, $sessDate);

//Get the day number out of 7 days
$weekdaynum = date('w', strtotime($sessDate));
// the following will handle what happens when a date falls on Sunday or Saturday.
// I DO NOT want to slide a week out in either direction
switch ($weekdaynum) {
case 0: // sunday
$startAtSun = strtotime('this sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));
case 6: // saturday
$startAtSun = strtotime('last sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));
default: // all other days
$startAtSun = strtotime('last sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));

$format = 'Y-m-d';
$week_start = date($format, $startAtSun);
$week_end = date($format, $endAtSat);

Thursday, November 2, 2017

Android Program for Making a Week View

To follow up on the previous post, now that I have a PHP/MySQL program ready to send proprietary calendar data to the Android app, I need a week view to receive each appointment. The work done on this GitHub code is tremendous and is a good start. https://github.com/AnilMH/Android-WeekView-Demo.
To be continued...

Tuesday, October 31, 2017

PHP Get Start of Current Week

I need to get the start and end date for the week of the current date.

$day = date('w');
$week_start = date('Y-m-d', strtotime('-'.$day.' days'));
$week_end = date('Y-m-d', strtotime('+'.(6-$day).' days'));

Saturday, September 23, 2017

Asus Zenfone Laser 2 - Lost Root Access

See about 3 posts ago. Anyhoos - This is where I have the files that I used to restore root: Google Drive. Of course, I used these files after resetting the device to factory.