CMPS 3350 Lab-13a

Android Studio App Delivery

Your goal for this lab is to produce a signed Android APK that resides on your own public web page,
and can be installed by a mobile-device user.

Step 1:
Start with your Android app from lab-13.

Create a signed Android Package (APK) for your app.
The apk should be created in release mode.

Android developer publish-your-page

Use the Android Studio menu and options to get this done.
Use online documentation or tutorials.

Place your final signed APK on a public Odin web page.

Name your web page:

    https://www.cs.csub.edu/~userid/3350/lab13.html

    where ~userid is your Odin account name.
    This equates to your /public_html/3350/ folder on Odin.
    There is no lab13 web folder. 

Please put your android apk file in the 3350 folder at:

    https://www.cs.csub.edu/~userid/3350/myapp.apk


Name the apk exactly: myapp.apk

Lower case .apk please.

Your instructor should be able to click on a web page element,
and install your app on a mobile Android device.

The web page hosting your app should...
   • be pleasing to the eye.
   • give technical information about your app.
   • help a user decide if your app will work for them.

Do not belittle or disrespect your own app on your page.

Sample web page

The page above is a sample.
You may look at the sample page.
Using the sample page as your own work will not get you much credit.


Steps 2 and 3 below are optional. Adding one or more features below shows extra effort.

helpful links:
sensors
network

Step 2:
Add a button to your app.

Set your button label to something like: "Contact Server"

When the button is clicked or touched, your program will read the
contents of a file on your own Odin server account, and display
the text contained there.

You may also contact a PHP file that returns some text.

You may use the graphical interface provided to show the text.

Below is sample code to draw graphics on a canvas (the screen).
public class MainActivity extends AppCompatActivity {
   ...
   protected void onCreate(Bundle savedInstanceState) {
      ...
      myView v;
      v = new myView(this);
      setContentView(v);
      ...
   }
   class myView extends View {
      private Paint paint;
      public myView(Context context) {
         super(context);
         init();
      }
      private void init() {
         paint = new Paint();
         paint.setStyle(Paint.Style.FILL_AND_STROKE);
         invalidate(); //causes a canvas draw
      }
      protected void onDraw(Canvas canvas) {
         paint.setColor(Color.rgb(255,255,0));
         paint.setStyle(Paint.Style.FILL);
         canvas.drawRect(0, 0, x, y, paint);
         paint.setTextSize(100);
         canvas.drawText("3350 Lab-11", 0, 0, paint);
      }
   }
}

Below is sample code to read a file from a web server.

Sources:

get-text-from-web-page-to-string

how-to-use-separate-thread-to-perform-http-requests

public class Thx implements Runnable {
   @Override
   public void run() {
      try {
         URL url = new URL("https://cs.csub.edu/~you/3350/some-file.txt");
         BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
         StringBuilder total = new StringBuilder();
         String line;
         while ((line = in.readLine()) != null) {
            total.append(line + " ");
         }
         strxx = total.toString();
         in.close();
      } catch (MalformedURLException e) {
      } catch (IOException e) {
      }
      return;
   }
};
Step 3:

Add code to your app that will display sensor information.

Some sample code for sensors is below.
The code implements listeners for an accelerometer and a gyroscope sensor.
Try to get it working in your app.

public class MainActivity extends AppCompatActivity implements SensorEventListener
{
   private SensorManager mSensorManager;
   private Sensor mAccelerometer;
   private Sensor mGyroscope;
   ...
   @Override
   public void onCreate(Bundle savedInstanceState) {
      ...
      mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
      mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
      ...
   }
   @Override
   protected void onResume() {
      super.onResume();
      mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
   }
   @Override
   protected void onPause() {
      super.onPause();
      mSensorManager.unregisterListener(this);
   }
   @Override
   public void onSensorChanged(SensorEvent event) {
      if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
         Toast.makeText( getApplicationContext(), "wiggle",
            Toast.LENGTH_SHORT ).show();
      }
   }
   ...
}
What to turn in?
Show Gordon your working program during lab session.
Save your project onto your laptop or a flash drive.

The source files for your apk should be on Odin server as:

    3350/d/activity_main.xml
    3350/d/MainActivity.java
    3350/d/string.xml