• No results found

Boutsis Ioannis Programming for Android

N/A
N/A
Protected

Academic year: 2021

Share "Boutsis Ioannis Programming for Android"

Copied!
16
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

History

Android is developed by the Open Handset Alliance led by

Google.

Google purchased the initial developer of the software,

(3)
(4)

Architecture

Applications

All applications are written using the Java programming language. ●

Application Framework

By providing an open development platform, Android offers developers the ability to build extremely rich and

innovative applications. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more.

Developers have full access to the same framework APIs used by the core applications. ●

Libraries

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework.

Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM relies on the Linux kernel for

underlying functionality such as threading and low-level memory management. ●

Linux Kernel

Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

(5)
(6)

Components

Activities

are basically a graphical component and there

should be a different activity for each UI screen of the

application.

Services

are used as background tasks (e.g. playing music

on the background) and they can be bind with a specific

activity.

Content Providers

are used to manage access on persistent

data that can be shared on different applications such as the

contacts phone numbers.

Broadcast Receivers

are used to receive a notification and

respond to that such as when receiving an SMS where the

appropriate Activity should be invoked.

Components communicate with messages called

Intents

,

(7)

Programming...

Android Manifest

XML based User Interface

Java Code

(8)

Android Manifest

Every application must have an AndroidManifest.xml file (with

precisely that name) in its root directory.

The manifest presents essential information about the

application to the Android system.

Activities, Permissions, Minimum Android Level, etc. should

be declared in the manifest.

More Info:

(9)

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".TestAndroidActivity" > <intent-filter >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"

/>

</intent-filter>

</activity>

<activity android:name=".Activity2" >

</activity>

</application> </manifest>

(10)

Resources(/res)

/drawables (low, medium, high)

/layout (xml Uis)

/values eg string.xml:

<?xml version="1.0" encoding="utf-8"?> <resources>

<string name="ds2011">Distributed Systems</string> <string name="button_enter">Enter</string>

<string name="click_android">Click on the android</string> <string name="changed_text">Text to be changed</string> <string name="app_name">TestAndroid</string>

(11)

Layouts

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/ apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/ds2011" android:textSize="20sp" android:textStyle="bold" android:gravity="center_vertical|center_horizontal"/> <ImageView android:id="@+id/androids" android:layout_width="234dp" android:layout_height="246dp" android:src="@drawable/android1" /> <Button android:id="@+id/button1" android:layout_width="150dp" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:text="@string/button_enter" /> </LinearLayout>

(12)

Layouts

activity2.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/ apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#330000" android:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/talking_android" android:layout_width="180sp" android:layout_height="80sp" android:layout_marginBottom="50sp" android:src="@drawable/android_look" /> <TextView android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:textSize="16sp" android:textStyle="italic" android:text="@string/click_android" /> <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:background="#000066" android:textColor="#ffcc00" android:typeface="monospace" android:text="@string/changed_text" /> </LinearLayout>

(13)

Java Code

TestAndroidActivity.java package com.test.android; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button;

public class TestAndroidActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button next = (Button) findViewById(R.id.button1);

next.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

Intent myIntent = new Intent(view.getContext(), Activity2.class);

startActivityForResult(myIntent, 0);

}

(14)

Java Code

Activity2.java package com.test.android; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

public class Activity2 extends Activity {

/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity2);

final ImageView iv =

(ImageView)findViewById(R.id.talking_android);

// set the listener

iv.setOnClickListener(new View.OnClickListener() { public void onClick(View view) {

androidClick(); }

}); }

private void androidClick() {

final AlertDialog.Builder alert = new AlertDialog.Builder(this);

final EditText input = new EditText(this); alert.setView(input);

alert.setPositiveButton("Change text", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString().trim(); changeText(value); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); }

private void changeText(String value) {

TextView tv = (TextView) findViewById(R.id.textView1); tv.setText(value);

Toast.makeText(getApplicationContext(), "Text changed!", Toast.LENGTH_SHORT).show();

} }

(15)
(16)

Διευθυνσιοδότηση

Στα κινητά οι διευθύνσεις ip δίνονται από το δίκτυο.

Για όσους χρησιμοποιούν τον emulator οι διευθύνσεις ip που χρησιμοποιεί είναι

διαφορετικές από αυτές του υπολογιστή

http://developer.android.com/guide/developing/devices/emulator.html#emulatornet

working

Έτσι, για να συνδεθεί ένας client στο ServerSocket του emulator πρέπει να γίνουν

τα εξής:

-το serverSocket του emulator ανοίγει στο port που θέλουμε(έστω 5000)

-Στη συνέχεια πρέπει να κάνουμε redirect κάποιο port σε αυτό.

Ανοίγουμε ένα telnet στο port που τρέχει ο emulator(πχ 5554) με telnet

localhost 5554

και εκτελούμε redir add tcp:5001:5000

-Τώρα κάθε client μπορεί να δημιουργήσει ένα socket για να συνδεθεί

στο αρχικό serverSocket με IP/port: 10.0.2.2:5001

References

Related documents

The growth in recognition of the Islamic education system, particularly Pesantren and Madrasah education, has brought new expectations and challenges for all stakeholders of

This report has been prepared independently of the company analysed by Close Brothers Seydler Research AG and/ or its cooperation partners and the analyst(s) mentioned on the

Product - Mobile as a Disrupter Mobile iOS App Mobile HTML Mobile Android App iPad . iOS App Tablet HTML

6 If so, the punishment seems to be so called “stick-and-carrot” type, which gives a severe damage.. It is noteworthy that the normalized winning bids are not so high in auctions

make java documentation android app building game android development nexus 7 2013 android sdk ndk ubuntu android apps development tools how to make calculator app in android

development training courses create your own android app easy android sdk ubuntu command line free android app builder no ads game engineer salary range android developer ebook

To assure lasting compliance on recidivist properties, the Neighborhood Services Unit will initiate non-complaint based exterior inspections, code enforcement on designated

The computed coefficient of multiple determination (R 2 ) value of 0.569 indicated that 56.9% of the total variation in commercial loans and advances (LCBLA) is accounted