Professional Documents
Culture Documents
INTRODUCTION
Android is a Linux-based operating system for mobile devices such as smartphones and
tablet computers. It is developed by the Open Handset Alliance led by Google. Google purchased
the initial developer of the software, Android Inc., in 2005.The unveiling of the Android
distribution in 2007 was announced with the founding of the Open Handset Alliance, a
consortium of 86 hardware, software, and telecommunication companies devoted to advancing
open standards for mobile devices. Google releases the Android code as open-source, under the
Apache License. The Android Open Source Project (AOSP) is tasked with the maintenance and
further development of Android .Android has a large community of developers writing
applications ("apps") that extend the functionality of the devices. Developers write primarily in a
customized version of Java. Apps can be downloaded from third-party sites or through online
stores such as Google Play (formerly Android Market), the app store run by Google.
Applications on an Android device dont need to be running to receive messages. The
system will wake up the application via Intent broadcast when the message arrives, as long as the
application is set up with the proper broadcast receiver and permissions. C2DM does not provide
any built-in user interface or other handling for message data. Instead, it simply passes raw
message data received straight to the application, which has full control of how to handle it. For
example, the application might post a notification, display a custom user interface, or silently
sync data. It requires devices running Android 2.2 or higher that also have the Market application
installed. It uses an existing connection for Google services. This requires users to set up their
Google account on their mobile devices. Each notification message size is limited to 1024 bytes,
and Google limits the number of messages a sender sends in aggregate, and the number of
messages a sender sends to a specific device.
FEASIBILIT STUDY
As we have discussed in the introduction this project is developed based on the Android
OS and google Cloud this project s theoretically feasibility is observed and we intended to
introspect whether our postulates and hypothesis about the construction of the project. On throw
study on this the following finding were evolved.
Technical Feasibility
As this project is aimed to use HTTP based device to device messaging with the help of
implementing GCM Cloud Connection Server (CCS) to interact with Android devices . GCM
Cloud Connection Server (CCS) is a connection server based on XMPP. CCS allows 3rd-party
app servers to communicate with Android devices by establishing a persistent TCP connection
with Google servers using the XMPP protocol. This communication is asynchronous and
bidirectional (device to device). So this instant messaging can be achieved with appropriate
server side programming and Android application which can interact with the cloud is required
which can be easily built. So we decided and made a conclusion at the feasibility study that this
project is technical feasibility.
SYSTEM ANALYSIS
Existing System
Presently existing system uses the cloud for push mail and chat and messaging services
like whatsapp and wechat etc. all these are based on concealed business logic and uses their
existing mail servers and messaging system in connection with google cloud for messaging. But
to develop such systems will be time consuming and multi protocol based programming to cater
to all sort of devices available in the market place. Even though majority of these services started
with the same intention of providing simple device to device messaging they were diverted and
become hevy weight application which may be having huge overheads while running on smart
phones. So majority of the users find it that these are making their phone performance to getting
slower. So they users tend to close the application and invoke when it is required. This
completely defeats the concept of instant messaging.
Proposed System.
The proposed system is to develop a application for sending device to device (Mobile To
Mobile) messaging using google cloud messaging (GCM). it is the very basic method one can
use this to create advance level messaging application. Using android and SQLite database.
This system will be using HTTP based device to device messaging but Right way to achieve the
device to device messaging is to implement GCM Cloud Connection Server (CCS) . GCM Cloud
Connection Server (CCS) is a connection server based on XMPP. It will be simple and will not
take overhead so Applications on an Android device dont need to be running to receive
messages. The system will wake up the application via Intent broadcast when the message
arrives, as long as the application is set up with the proper broadcast receiver and permissions.
C2DM does not provide any built-in user interface or other handling for message data. Instead, it
simply passes raw message data received straight to the application, which has full control of
how to handle it.
SYSTEM REQUIREMENTS
HARDWRE REQUIRMENTS
For Development :
PC with Intel Duel Core Processor
Minimum of 4 GB RAM
500 GB HDD
VGA Card With Built in Video RAM
For Testing
Tablet PC or Smart phone with Sensors which adhering to th standards of Nexus 5
or above
SOFTWARE REQUIREMENTS
Either Windows 7 or Ubuntu 13
Software Development
Android ADK Studio
Android Development Kit Bundle 4.4 or later
Android OS 4.41 KIT KAT
Google Cloud Account
SQLite Database
SYSTEM DESCRIPTION
WORKFLOW:
PROJECT STRUCTURE
The Linux kernel, the libraries and the runtime are encapsulated by the application
framework. The Android application developer typically works with the two layers on top to
create new Android applications.
Similar to the JVM, Dalvik optimizes the application at runtime. This is known as Just In
Time (JIT) compilation. If a part of the application is called frequently, Dalvik will optimize this
part of the code and compile it into machine code which executes much faster.
The Java source files are converted to Java class files by the Java compiler.
The Android SDK contains a tool called dx which converts Java class files into a .dex (Dalvik
Executable) file. All class files of the application are placed in this .dex file. During this
conversion process redundant information in the class files are optimized in the .dex file.
For example, if the same String is found in different class files, the .dex file contains only one
reference of this String.
These .dex files are therefore much smaller in size than the corresponding class files.
The .dex file and the resources of an Android project, e.g., the images and XML files, are packed
into an .apk (Android Package) file. The program aapt (Android Asset Packaging Tool) performs
this step.
The resulting .apk file contains all necessary data to run the Android application and can be
deployed to an Android device via the adb tool.
The Android SDK contains an Android device emulator. This emulator can be used to run
an Android Virtual Device (AVD), which emulates a real Android phone. Such an emulator is
displayed in the following screenshot.
AVDs allow you to test your Android applications on different Android versions and
configurations without access to the real hardware.
During the creation of your AVD you define the configuration for the virtual device. This
includes, for example, the resolution, the Android API version and the density of your display.
You can define multiple AVDs with different configurations and start them in parallel. This
allows you to test different device configurations at once.
Source Code :
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidexample.mobilegcm"
android:versionCode="1"
android:versionName="1.0" >
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<!-- Main activity. -->
<application
android:name="com.androidexample.mobilegcm.Controller"
android:icon="@drawable/user_thumb"
android:label="@string/app_name" >
<!-- Register Activity -->
<activity
android:name=".Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="com.androidexample.mobilegcm" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity"></activity>
<!-- Main Activity -->
<activity
android:name="com.androidexample.mobilegcm.MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name" >
</activity>
<activity android:name=".GridViewExample" android:screenOrientation="portrait"></activity>
<activity android:name=".SendPushNotification" android:screenOrientation="portrait"></activity>
<activity android:name=".ShowMessage" android:screenOrientation="portrait"></activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidexample.mobilegcm" />
</intent-filter>
</receiver>
<service android:name="com.androidexample.mobilegcm.GCMIntentService" />
</application>
<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.androidexample.mobilegcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidexample.mobilegcm.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
</manifest>
// setting id
public void setID(int id){
this._id = id;
}
// getting imei
public String getIMEI(){
return this._imei;
}
// setting imei
public void setIMEI(String imei){
this._imei = imei;
}
// getting name
public String getName(){
return this._name;
}
// setting name
public void setName(String name){
this._name = name;
}
// getting Message
public String getMessage(){
return this._message;
}
// setting Message
public void setMessage(String message){
this._message = message;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "UserInfo [name=" + _name + "]";
}
}
user
and
package com.androidexample.mobilegcm;
import
import
import
import
import
import
import
import
import
import
import
java.util.ArrayList;
java.util.List;
com.androidexample.mobilegcm.UserData;
android.content.ContentValues;
android.content.Context;
android.database.Cursor;
android.database.DatabaseUtils;
android.database.SQLException;
android.database.sqlite.SQLiteDatabase;
android.database.sqlite.SQLiteOpenHelper;
android.util.Log;
= "user_name";
message
specific
funtions.
/**** Database Version (Increase one if want to also upgrade your database) ****/
public static final int DATABASE_VERSION = 1;// started at 1
protected DBAdapter() {
}
/******************* Initialize database *************/
public static void init(Context context) {
if (DBHelper == null) {
if (DEBUG)
Log.i("DBAdapter", context.toString());
DBHelper = new DataBaseHelper(context);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (DEBUG)
Log.w(LOG_TAG, "Upgrading database from version" + oldVersion
+ "to" + newVersion + "...");
} catch (Throwable t) {
Log.i("Database", "Exception caught: " + t.getMessage(), t);
}
}
cursor.close();
// return contact list
return contactList;
}
data.setIMEI(cursor.getString(0));
data.setName(cursor.getString(1));
// Adding contact to list
contactList.add(data);
} while (cursor.moveToNext());
}
cursor.close();
return contactList;
}
if (null != aString) {
//aReturn = aString.replace("'", "''");
aReturn = DatabaseUtils.sqlEscapeString(aString);
// Remove the enclosing single quotes ...
aReturn = aReturn.substring(1, aReturn.length() - 1);
}
return aReturn;
}
// UnEscape string for single quotes (show data)
private static String sqlUnEscapeString(String aString) {
String aReturn = "";
if (null != aString) {
aReturn = aString.replace("''", "'");
}
return aReturn;
}
}
java.io.IOException;
java.io.OutputStream;
java.net.HttpURLConnection;
java.net.MalformedURLException;
java.net.URL;
java.util.ArrayList;
java.util.HashMap;
java.util.Iterator;
java.util.Map;
java.util.Random;
java.util.Map.Entry;
import com.google.android.gcm.GCMRegistrar;
import
import
import
import
import
import
import
import
import
android.app.AlertDialog;
android.app.Application;
android.content.Context;
android.content.DialogInterface;
android.content.Intent;
android.net.ConnectivityManager;
android.net.NetworkInfo;
android.os.PowerManager;
android.util.Log;
params.put("regId", regId);
params.put("imei", IMEI);
try {
post(serverUrl, params);
GCMRegistrar.setRegisteredOnServer(context, false);
String message = context.getString(R.string.server_unregistered);
displayRegistrationMessageOnScreen(context, message);
} catch (IOException e) {
ConnectivityManager connectivity =
(ConnectivityManager) getSystemService(
Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
return false;
}
if(status != null)
// Set alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Set OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Show Alert Message
alertDialog.show();
}
private PowerManager.WakeLock wakeLock;
public void acquireWakeLock(Context context) {
if (wakeLock != null) wakeLock.release();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, "WakeLock");
wakeLock.acquire();
}
public void releaseWakeLock() {
if (wakeLock != null) wakeLock.release(); wakeLock = null;
}
// Get UserData model object from UserDataArrlist at specified position
public UserData getUserData(int pPosition) {
return UserDataArr.get(pPosition);
}
// Add UserData model object to UserDataArrlist
public void setUserData(UserData Products) {
UserDataArr.add(Products);
}
//Get Number of UserData model object contains by UserDataArrlist
public int getUserDataSize() {
return UserDataArr.size();
}
// Clear all user data from arraylist
public void clearUserData() {
UserDataArr.clear();
}
}
Screen Shots:
NOTE : If you will not add google account in your device and run this example you will get gcm error
account_missing.see this screenshot
TESTING:
The assertion methods are from the JUnit Assert class. Generally, you can use
assertions to verify if a specific condition that you want to test is true.
If the condition is false, the assertion method throws an AssertionFailedError exception, which is
then typically reported by the test runner. You can provide a string in the first argument of your
assertion method to give some contextual details if the assertion fails.
If the condition is true, the test passes.
build and run project test easily from the Package Explorer in Eclipse.
To build and run your test:
1. Connect an Android device to your machine. On the device or emulator, open the Settings menu,
select Developer options and make sure that USB debugging is enabled.
2. In the Project Explorer, right-click on the test class that created earlier and select Run As >
Android Junit Test.
3. In the Android Device Chooser dialog, select the device that just connected, then click OK.
4. In the JUnit view, verify that the test passes with no errors or failures.
In both cases, the test runner proceeds to run the other test methods in the test case.
An Activity unit test is an excellent way to quickly verify the state of an Activity and its
interactions with other components in isolation (that is, disconnected from the rest of the
system). A unit test generally tests the smallest possible unit of code (which could be a method,
class, or component), without dependencies on system or network resources. For example, you
can write a unit test to check that an Activity has the correct layout or that it triggers an Intent
object correctly.
Unit tests are generally not suitable for testing complex UI interaction events with the system.
Instead, you should use the ActivityInstrumentationTestCase2 class, as described in Testing UI
Components.
MAINTENANCE
Maintenance of Android Application
Keep clean caches Caches are good to keep certain information and have access to these faster
but with these files and information some "garbage" is stored . The solutions to this can be pretty
basic or advanced, the most basic way is to enter Application Manager (Settings> Applications>
Manage Applications) and clear the cache for each application. It is important to clear the cache
only and not application data as these may be important such as the files that resemble progress
in a game. Already the most advanced solution is to clear the Dalvik Cache and Cache Partition
through recovery.Both solutions dont need to be made with daily frequency, for example I
usually clean my caches every 45 days or when I feel that the phone is getting slow.
Full backups (full system backup) like those made by recovery or nandroid are great to store
complete setups but when they are done with dirty files in the the phones memory restoring
these files may worsen rather than help the situation of device
Ideally, do a full backup after completely configure phone (configure account, set homescreens,
install the required applications, etc.) but before using it for real.
That way if phone starts getting slow and nothing works to reverse the situation it can easily go
back to it's original settings without the hassle of customizing everything in its way again.
Do not touch the CPU / GPU the first dayLike people, phones also take a while to adapt to a
new environment, or in our case new ROMs, so during the first 24 hours of use is important to
use the settings of CPU and GPU that came with the ROM, no overclock, undervolt and things
like that.
Another important step in the process of adaptation to the new ROM is really using and
exploring the device in this very first day so it "get used" to the change. Do not mind the battery
consumption, that should stabilize after a few days.
Its also iimportant to remember that some ROMs already comes with overclock, undervolt and
improvements in battery usage. In this case there is no problem in using these settings from the
first minute because if they are there since the installation of the ROM, it is because they are part
of the default settings already programmed and develop on this particular ROM and it will work
better this way.
Use the maximum batteryBatteries seem to last less and less as time goes on, in part this is
because battery is uncalibrated and there are ways to fix it.
Applications: less is more Having millions of apps is the glory and the doom of smartphones,
the glory because it can do everything on device and doom because of the following reasons:
As a computer a phone also slows down the as it becomes full and in most cases blame it on the
number of apps that havebeen installed on it. So try to leave installed only the applications
actually use and uninstall the ones that no longer use so can have more free memory and
consequently a faster device.
Some applications can not be uninstalled because they are system applications; in order to
remove those apps are going to need uninstallers that have root access (ex: RootUninstaller)
which are capable of removing these applications but before taking such a measure is necessary
to look for a safelist (a list of applications that can be removed without causing system
problems).
Keeping a low number of applications but doing so by installing and uninstalling new apps every
day also usually let the machine slower so if it find an application for a specific function that fits
needs one should stay with it instead of testing another 10 before returning to it
PS: A good way to avoid testing several applications before finding the right one is reading
reviews and comments before making onece choice
Repair defective applicationsOften the phone is working fine but a certain application or
function is not, which can cause slowdowns and FCs (force close); depending on the situation
there is not much to do but some of these solutions may take care of the problem:The first thing
to do is to uninstall and reinstall the apps via Play Store to make sure that the problem was not
caused by a corrupted file when downloaded the application, if the problem persists there are
some more advanced alternatives: in the advanced settings of recovery select fix permissions,
this function should make sure that every application has the necessary permissions to work
properly Keep some free spaceFull memory is often a problem on any device, especially in
older phones like ours, after all the more files the longer it takes read all these files if it is
necessary, so the tip is this: the more free space the better.
Avoid keeping some applications running all the timeIts very common to close an
application and assume that it stopped running on the system but this is not always the case
because it actually still cached in the memory of the device, Android makes it to be faster on
reopening it later and often the system itself definitively closes the application automatically but
thats not always the case.Firstly it is important to prevent certain applications from even
opening and to do this we use apps known as Startup Managers, there are several options in the
Play Store but I particularly like Autostarts. Once inside the Startup Manager one can choose
which applications will be opened as the system is started or any action is taken (for example
changing the state of your Wi-Fi); the ideal is to minimize the number of self-starting
applications, leaving only the truly necessary ones without forgetting to be very careful to avoid
stopping system applications because if they are unable to open themselves it can cause
instability. Another way to prevent applications from opening or stay on cache all the time is to
disable automatic updates of apps such as email clients and social networks but this is a more
personal matter that varies from user to user,
It's easy to know when to quit an application completely but it is necessary to first understand a
basic concept about the system: applications and processes cached in memory are not always a
bad thing, in fact as stated at the beginning of the topic they are a good thing because the
application should open faster when launched again (hence the use of Task Killers usually
worsens more than help if not done properly) but if use an application to view the weather every
morning and will only use it again the next morning this application can be closed without
problems.
CONCLUSION
As it is intended in the Device To Device Messaging Using Google Cloud Messaging GCM Android Application has been developed and tested with Android KIT KAT OS and successfully
running. As initially planed this project was developed as light weight app which will not be
continuously running on android phones but once the message is received the intent will be
created and it will invoke this activity. Thus a robes application which uses PHP as the server
side and JAVA programming for android in devices makes the program to run effectively with
high security and reliability.
FUTURE ENHANCEMENTS
Even though the project is developed successfully it is observed that the following enhancement
and changes will make this project as more effective. The suggested and observed future
enhancements are :
BIBLIOGRAPHY
Google inc 2014, Android Quick Start Guide
Frank Zammetti -2013. Apress,Specifications of Pro IOS and Android Apps for
Business: With Jquery Mobile, Node.Js, and Mongodb