Vous êtes sur la page 1sur 45

BEEP- AN ANONYMOUS REPORTING

SYSTEM
A MINI PROJECT REPORT
Submitted by

PRAVEEN RAJ.M

(1301106)

SACHIDHANDHANAM.R

(1301163)

MOHAMMED AKHIL.S

(1301048)

In partial fulfillment for the award of the degree


Of

BACHELOR OF ENGINEERING
In
COMPUTER SCIENCE AND ENGINEERING

SRI RAMAKRISHNA ENGINEERING COLLEGE


COIMBATORE-641022
APRIL 2016

DECLARATION
We affirm that the project work titled BEEP- AN ANONYMOUS
REPORTING SYSTEM being submitted in partial fulfillment for the award
of Bachelor of Engineering is the original work carried out by us. It has not
formed the part of any other project work submitted for award of any degree or
diploma, either in this or any other University.

-----------------------------------------------------(Signature of the Candidates)


PRAVEEN RAJ.M

(1301106)

SACHIDHANDHANAM.R (1301163)
MOHAMMED AKHIL.S

(1301048)

I certify that the declaration made above by the candidates is true.

-----------------------------Signature of the Guide,


Dr.B.Mathivanan,Ph.d.,
Associate Professor,
Department of CSE.

TABLE OF CONTENTS

CHAPTER
NO.

TITLE
ABSTRACT
LIST OF FIGURES
LIST OF ABBREVATIONS

1.
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
2.
2.1
3.
3.1

3.2

3.3

4.
4.1

INTRODUCTION
Introduction about Android Platform
Overview
Significance of Android
Architecture of Android Architecture
Applications of Android
Introduction of the project
Problem Statement
Objective of the project

PAGE NO.
V
VI
VII
1
1
1
2
2
3
4
4
4

LITERATURE REVIEW
SMS based alert system

5
5

SYSTEM ANALYSIS

Existing System
3.1.1 Disadvantage of Existing
System
Proposed System
3.2.1 Advantage of Proposed
System
Methodology and Development

SYSTEM SPECIFICATION
System Requirements
4.1.1 Hardware Requirements
4.1.2 Software Requirements

8
8
8
8

6
6
6
6

4.2

5.
5.1
5.2

6.

TABLE OF CONTENTS
Software Specification
4.2.1 About JDK
4.2.2 JDK Implementing Languages 4
4.2.3 Architecture of JDK

8
8
9
10

SYSTEM IMPLEMENATION
List of Modules
Module Description
5.2.1 Login Module
5.2.2 QR Code Module
5.2.3 Parse Module
5.2.4 Sinch Module

15
15
15
15
15
16
16

CONCLUSION & FUTURE WORK


I
II
III
IV

APPENDICES
Login Module
QR Code Module
Parse Module
Sinch Module

17
18
21
27
33

ABSTRACT
Historically, Interacting with government authorities has been a troublesome
process. Be it the consequences of making a complaint or the amount of time it
consumes and who may care attitude. Due to this a huge rift has been created
between the public and the authorities. The system which is used currently for
communication between the two parties are direct face to face communication
or through means of phone. Even though this system is functioning moderately,
its way outdated. For the currently technological life we live in, We need to
update ourselves to its standards. This paved the way for development of Beep.
Beep is a social application which acts as middleman between the public and
authority. The user can request or report a mishappening and the authorities can
respond to it or make a announcement and so on. The user should sign up for a
profile with aadhar card number for legitimacy purpose and to avoid fake
profiles. Which in turn provides a strong authentication mechanism.

LIST OF FIGURES

SL. No.

TITLE

PAGE NO.

1.1

Architecture of Mobile Application

1.2

Java Virtual Machine

1.3

New portable Java Compile-Time Environment

1.4

Functional relationship of JIT

1.5

Solaris JVM Functional Relationship

LIST OF ABBREVIATION

IDE

Integrated Development Environment

SDK

Software Development Kit

ADT

Android Development Tools

APK

Android Package Kit

CHAPTER 1
INTRODUCTION

Introduction about Android Platform


Android system in the electronics market is becoming more and more
popular, especially in the Smartphone market. Because of the open source, some
of the development tools are free, so there are plenty of applications generated.
This greatly inspired the people to use Android system. In addition, it provides
very convenient hardware platform for the developers so that they can spend
less effort to realize their ideas. This makes Android can get further
development.
Overview
The applications on the market today mostly commercial applications and
contain a large number of built-in advertising. If the user prefers to remove the
built-in advertising, a certain price must be to paid to reach that and this is not
convenient. Meanwhile, because of the unfair competition of IT, many
applications built illegal program to steal user information and cause some
damage to user's personal privacy. Sometimes, users will pay more attention to
the user experience of software. Therefore, the development of the application
can not only be limited to the function, more attention should be paid to the
user's experience. After studying some previous Android applications and access
to large of materials, we utilize the Java language, the Android studio , Android
ADT and the Android SDK to develop these mobile applications. These system
have a nice interface and smooth operation. These Apps won't steal any personal

information, but can exclude useless information and bring a wonderful user
experience.
Significance of Android
It's a platform for building and channeling inventory, much like web
browser.
The declarative XML enables developers and handset manufacturers to
rapidly develop the user interface for new applications.
Every application on Android is a Web 2.0 citizen.
Android allows developers to program against the familiar JAVA SE
library of APIs ( The desktop version of the java Libraries), which is
much broader and more powerful than Java ME, mobile version.
Android is not only a departure from Java ME development model, but
also away from Linux development.
Android seems to be the only non-proprietary operating system with
strong chance of wider commercial adoption.
Architecture of Android Application
The Android system architecture. Android system is a Linux-based
system, Use of the software stack architecture design patterns. The Android
architecture consists of four layers : Linux kernel, Libraries and Android
runtime, Application framework and then Applications.
Each layer of the lower encapsulation, while providing call interface to the
upper.

10

Fig 1.1 The typical architecture of Android Platform


The main components of an android platform include Linux Kernel which in
turn consists of the display driver, Camera Driver and Usb Driver. Secondly,
The Libraries which includes the surface manager and the media framework.
The Android Runtime which has the core libraries. The application framework
consists of the Activity manager, windows manager and then the content
provider.
Applications of Android
Android initially came into existence with the sure fire idea that
developments are given the power and freedom to create enthralling Mobile
applications while taking advantage of everything that the mobile handset has to
offer.
Android is built on open Linux Kernel. This particular software for
Mobile Application is made to be open source, thereby giving opportunity to
the developers to introduce and incorporate any technological advancement.
Build on custom virtual machine android gives its users the addition usage and
application power, to initiate an interactive and efficient application and
11

operational software for your phone. Google's mobile operating device, the
android is its awesome creation in the definitive creation of Software
Application for the mobile phone arena it also facilitates the g-juice in your
mobile thus initiating a whole new world of Mobile Technology experience by
its customers.
Introduction of the project
Android is comprehensive software stack of mobile devices that includes an
operating system, middleware and key application. This rich source of software
bunch is used in Mobile Technology through its innovation module of The
Android Software Development Kit (SDK). To develop an application in this
platform that offers information on the technical symposiums and workshop
happening in and around the city.
Problem Statement
To overcome the difficulties in existing sms-based reporting system and
to provide anonymity for the whistle-blowers and their reports.
Objective of the project
For a long time, the citizens of India have had the inner urge to stop
illegal activities happening around us. But due to consequences and fear, we
were bogged down to being a idle rock. This gave us the thought to take an
initiative to bridge the rift between the authorities and the public. This paved the
way for the development of Beep. It acts as a middleman between the
authorities and public. Beep is a app the City deserves, the one it needs right
now. So well develop it. Because its not our hero, Its a silent guardian, a
watchful protector.

12

CHAPTER 2
LITERATURE REVIEW
SMS Based Alert System
Hyderabad Police Department
Information received by the Police Control Room will be sent as an alert
through SMS to the Hyderabad City Police Department. Citizen can lodge a
complaint by sending an SMS to 9010100100 using key words such as TTraffic, Te-Terror, W- Women, C-Crime, Others . The received SMS will be
stored in a database and a voice alert is received by the staff of Control room.
As per the request from complainant, it will be forwarded to the concerned
Officer /Group of Officers.
.
.

13

CHAPTER 3
SYSTEM ANALYSIS
Existing System
Already existing systems are phone call, face to face and SMS. Phone and
face-to-face communication has been the most orthodox and frequently used
methodologies. SMS system has been lately integrated to assist with interaction.
Disadvantages of Existing System
Phone and face-to-face communication has been time consuming
These system has issues of fake calls and no acknowledgment system.
Proposed System
The Beep is an android application. It creates a messaging platform for
the users and authorities. It can be used on both smart phones as well as
computer systems. It integrates functionality of the existing systems making it
faster and efficient. The user can sign up for a profile which will be validated
through means by aadhar card code. The user can log in with the verified user Id
and can send/receive messages to/from the authority.
Advantages of Proposed System
Better interaction between police department and public.
Easier to use and communicate.
Provides security to the whistleblower and anonymity.
Methodology and Development
Today there are number of IDE (Integrated Development Environment)
for building android applications, of those the widely used on are ECLIPSE and
the new IDE from the GOOGLE is "ANDROID STUDIO". To utilize the
features more efficiently, we developed the application in Android Studio
IDE.IT is shipped with in-built base workspace and an extensible plug-in
system for customizing the environment. Written mostly in java, Studio can be
used to develop applications. Various APIs can be integrated to the applications
to increase the applications functionality. By using different plug-ins, Studio
may also be used to develop application in other programming languages : Ada,
14

ABAP, C, C++, COBOL, FORTAN, Haskell, Java Script, Lasso, Perl, PHP,
Python, R, Ruby(including Ruby on Rails framework), Scala, Clojure, Groovy,
Scheme, and Erlang. Development environments include the Eclipse Java
development tools (JDT) for Java and Scala, Eclipse CDT for C/C++ and
Eclipse PDT for PHP, among others.
DATABASE
The database we used to create this project Parse. Parse is back-end tools
for mobile developers that help mobile developers store data in the cloud,
manage identity log-ins, handle push notifications and run custom code in the
cloud. Parse is reportedly powering 500,000 mobile apps.

CHAPTER 4
15

SYSTEM REQUIREMENT
HARDWARE REQUIREMENT
Processor

: Intel Core i3 and above

Hard Disk

: 200 GB

RAM

: 4 GB

Video

: 1014 * 768 resolutions

SOFTWARE REQUIREMENT
Operating System : Windows XP/7/8
Tools

: Java Development Kit

Front End

: Android Studio IDE

Back End code

: Parse and Sinch

Software Specification
About JDK
The Java Development Kit (JDK) is an implementation of either on of the
Java SE, or Java ME platforms released by Oracle corporations in the form of
binary product aimed at Java developers on Solaris, Linux, Mac OS X or
Windows. The JDK includes a private JVM and a few other resources to finish
the recipe to a Java Application. Since the introduction of the Java platform, it
has been by far the most widely used Software Development kit (SDK). On 17
November 2006, Sun announced that it would be released under the GNU
General Public License (GPL), thus making it free software. This happened in
large part on 8 May 2007, when Sun contributed the source code to Open JDK.

16

Java Developers are initially presented with two JDK tools java and javac. Both
are run from the command prompt, Java source files are simple text files saved
with extension of java. After writing and saving Java source code, the javac
compiler is invoked to create .class files. Once the .class files are created, the
'java' command can be used to run the java program.
For developers who wish to work in an integrated development environment
(IDE), a JDK bundled with Netbeans can be downloaded from Oracle website.
Such IDEs speed up the development process by introducing point-and-click
and drag-and-drop features for creation.
There are different JDKs for various platforms. The supported platforms include
Windows, Linux and Solaris. Mac users need a different software development
kit, which includes adaptations of some tools found in the JDK.
JDK implementing languages
The Java SE platform enables the development of applications with the
following features:
Can be written once and run anywhere
Can be run securely because of the Java sandbox security model
Easy to package and deliver
The Java SE platform also provides robust support with respect to the following
areas( and more):

Concurrency
Garbage Collection
Reflective access to classes and objects
JVM TOOL Interface ( JVM TI): A native programming interface for use
by tools. It provides both a way to inspect the state and to control the
execution of application running in the JVM.

17

Oracle's HotSpot JVM also offers the following tools and features :
DTrace:A Comprehensive dynamic tracing utility that monitors the
behavior of the applications programs as well as operating system itself.
Performance optimizations
PrintAssembly: A Java HotSpot option that prints assembly code for
bytecoded and native methods.
The Java SE 7 platform enables non-Java languages to exploit the infrastructure
and potential performance optimizations of JVM. The Key mechanism is the
invoke dynamic instruction, which simplifies the implementation of compilers
and runtime system for dynamically typed languages on the JVM.
Architecture of JDK
As the name suggest it's a Kit and it contains all the software components
used for compiling, documenting, and executing Java programs. It's basically a
logical collection of the The Java Programming Language, JRE (JVM + Java
APIs), and Tools & Tool APIs, which include java, javac, javadoc, apt, jar,
javap, Deploy, Monitoring, Java VisualVM, Scripting, etc.
JRE Components
The JRE is the software environment in which programs compiled for a
typical JVM implementation can run. The runtime system includes:
Code necessary to run Java programs, dynamically link native methods, manage
memory and handle exceptions.
Implementation of the JVM
The following figure shows the JRE and its components, including a
typical JVM implementation's various modules and its functional position with
respect to the JRE and class libraries.
18

Typical JVM's Implementation

Fig.4.1:Functional Relationship to JRE and Class Libraries


JVM
The JVM is an abstract computing machine, having an instruction set that
uses memory. Virtual machines are often used to implement a programming
language. The JVM is the cornerstone of the Java programming language. It is
responsible for Java's cross-platform portability and the small size of its
compiled code.
The Solaris JVM is used to execute Java applications. The Java
compiler, javac, outputs bytecodes and puts them into a .class file. The JVM
then interprets these bytecodes, which can then be executed by any JVM
implementation, thus providing Java's cross-platform portability. The next two
figures illustrate the traditional compile-time environment and the new portable
Java compile-time environment.

19

Fig.4.2:Java Virtual Machine

Fig.4.3:New Portable Java Compile-Time Environment

Multithreading JVM
The Java programming language requires that multithreading (MT) programs be
supported. All Java interpreters provide an MT programming environment.
However, many of these interpreters support only uniprocessor multithreading,
so Java program threads are executed one at a time.
The Solaris JVM interpreter takes full advantage of multiprocessor systems by
using the intrinsic Solaris multithread facilities. These allow multiple threads of
a single process to be scheduled simultaneously onto multiple CPUs. An MT

20

Java program run under the Solaris JVM will have a substantial increase in
concurrency over the same program run on other platforms.
Sun Just-In-Time (JIT) Compiler
The Sun Java JIT compiler, an integral part of the Solaris JVM, can accelerate
execution performance many times over previous levels. Long-running,
compute-intensive programs show the best performance improvement.
JIT Compile Process
When the JIT compiler environment variable is on (the default), the JVM reads
the .class file for interpretation and passes it to the JIT compiler. The JIT
compiler then compiles the bytecodes into native code for the platform on
which it is running. The next figure illustrates the JIT compile process.

Fig.4.4:Shows the functional relationship of the JIT to the Solaris JVM and
JRE
21

Fig.4.5:Solaris JVM Functional Relationship to the JIT Compiler

CHAPTER 5
SYSTEM IMPLEMENTATION
List of Modules
Login Module
QR code Module
Parse Module
Sinch Module
Module Description
Login Module
The login module allows the user to login through the registered profile
details. After logging in, the user has full access to the functionalities of the
applications. If the user doesn't have a registered profile, then the user has to

22

create a new profile through signup option. The login module is the gateway to
applications features. The
QR Code Module
If the user doesn't have a profile, he can create profile through sign up
option. The sign up option asks the user for Name, Data of birth and Aadhaar
card number. After entering those detail and submitting it, it will call QR API
which will scan the aadhaar card's barcode and compares it with entered details.
The details are validated. If the details are legitimate , the data is stored in the
database and new profile is created else the is registration rejected.

Parse Module
The database we used to create this project Parse. Parse is back-end tools
for mobile developers that help mobile developers store data in the cloud,
manage identity log-ins, handle push notifications and run custom code in the
cloud. Parse is reportedly powering 500,000 mobile apps. It's an API which can
be integrated along with android studio code.

Sinch Module
Sinch allows developers to quickly and easily add voice, instant
messaging and SMS features to their apps, using their SDK and REST API. This
allows developers to let their apps make and receive phone calls, instant
messages and text messages within their apps. It's an API which can be
integrated along with android studio code. Through this Module, the police and
the public can interact with each other through messages.

23

CHAPTER 6
CONCLUSION AND FUTURE WORK
In this project, We have proposed an application that provides messaging
interface between the police and public. In future, we are planning to add
additional features such as location sharing and also to optimize the application
further more by integrating more API's.

24

APPENDICE-I
LOGIN MODULE
package com.sinch.messagingtutorial.app;
import
import
import
import
import
import
import

android.app.Activity;
android.content.Intent;
android.os.Bundle;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.Toast;

import com.parse.LogInCallback;
import com.parse.ParseUser;
public class LoginActivity extends Activity {
private
private
private
private
private
private
private
private
private
private
private

Button b2;
Button loginButton;
Button signupbutton;
EditText usernameField;
EditText passwordField;
String username;
String password;
Intent intent;
Intent serviceIntent;
Intent newintent;
Intent displayintent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
intent = new Intent(getApplicationContext(), ListUsersActivity.class);
serviceIntent = new Intent(getApplicationContext(),
MessageService.class);

25

newintent = new Intent(getApplicationContext(),SignUpActivity.class);


displayintent = new
Intent(getApplicationContext(),DisplayActivity.class);
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
startService(serviceIntent);
startActivity(intent);
}
setContentView(R.layout.activity_login);
;
loginButton = (Button) findViewById(R.id.loginButton);
signupbutton = (Button) findViewById(R.id.signup);
//b2= (Button) findViewById(R.id.button2);
usernameField = (EditText) findViewById(R.id.loginUsername);
passwordField = (EditText) findViewById(R.id.loginPassword);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
username = usernameField.getText().toString();
password = passwordField.getText().toString();
ParseUser.logInInBackground(username, password, new
LogInCallback() {
public void done(ParseUser user, com.parse.ParseException
e) {
if (user != null) {
startService(serviceIntent);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(),
"Wrong username/password combo",
Toast.LENGTH_LONG).show();
}
}
});
}
});
signupbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
startActivity(newintent);
}
});

}
//public void bu(View vu){
// startActivity(new Intent(LoginActivity.this,SignUpActivity.class));
//}
@Override
public void onDestroy() {
stopService(new Intent(this, MessageService.class));
super.onDestroy();
}
}

26

27

APPENDICE-II
QR-CODE MODULE
package com.sinch.messagingtutorial.app;
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.content.Intent;
android.content.pm.ActivityInfo;
android.hardware.Camera;
android.hardware.Camera.AutoFocusCallback;
android.hardware.Camera.PreviewCallback;
android.hardware.Camera.Size;
android.os.Bundle;
android.os.Handler;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.FrameLayout;
android.widget.TextView;

import
import
import
import
import

net.sourceforge.zbar.Config;
net.sourceforge.zbar.Image;
net.sourceforge.zbar.ImageScanner;
net.sourceforge.zbar.Symbol;
net.sourceforge.zbar.SymbolSet;

import
import
import
import
import
import

org.w3c.dom.Attr;
org.w3c.dom.Document;
org.w3c.dom.Element;
org.w3c.dom.NamedNodeMap;
org.w3c.dom.NodeList;
org.xml.sax.SAXException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

28

import javax.xml.parsers.ParserConfigurationException;
/* Import ZBar Class files */
public class CameraTestActivity extends Activity
{
private Camera mCamera;
private CameraPreview mPreview;
private Handler autoFocusHandler;
private StringBuffer output = new StringBuffer(150);
private String[] attrNames = new String[150];
private String[] attrValues = new String[150];
private String name;
private String no;
private String dob;
TextView scanText;
Button scanButton;
private String str;
//String str1;
//private String sStringToParse;
ImageScanner scanner;
private boolean barcodeScanned = false;
private boolean previewing = true;
static {
System.loadLibrary("iconv");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent gotintent = getIntent();
name = gotintent.getStringExtra("txtname");
dob = gotintent.getStringExtra("txtdob");
no = gotintent.getStringExtra("txtno");

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview);
preview.addView(mPreview);
scanText = (TextView)findViewById(R.id.scanText);

29

scanButton = (Button)findViewById(R.id.ScanButton);
scanButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (barcodeScanned) {
barcodeScanned = false;
scanText.setText("Scanning...");
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
previewing = true;
mCamera.autoFocus(autoFocusCB);
}
}
});
}
public void onPause() {
super.onPause();
releaseCamera();
}
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
Camera c = null;
try {
c = Camera.open();
} catch (Exception e){
}
return c;
}
private void releaseCamera() {
if (mCamera != null) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
}
}
private Runnable doAutoFocus = new Runnable() {
public void run() {
if (previewing)
mCamera.autoFocus(autoFocusCB);
}
};
PreviewCallback previewCb = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);

30

if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms) {
scanText.setText("barcode result " + sym.getData());
output.append(sym.getData());
barcodeScanned = true;

}
str=output.toString();
str = str.replace("\"", "\'");
//str1 = str.replace("\'", " ");
String sStringToParse = new String(str);
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document doc = null;
try {
doc = db.parse(new
ByteArrayInputStream(sStringToParse.getBytes("utf-8")));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NodeList nlRecords =
doc.getElementsByTagName("PrintLetterBarcodeData");
int num = nlRecords.getLength();
for (int i = 0; i < num; i++) {
Element node = (Element) nlRecords.item(i);
//System.out.println("List attributes for node: " +
node.getNodeName());
// get a map containing the attributes of this node
NamedNodeMap attributes = node.getAttributes();
// get the number of nodes in this map
int numAttrs = attributes.getLength();

31

for (int j = 0; j < numAttrs; j++) {


Attr attr = (Attr) attributes.item(j);
attrNames[j] = attr.getNodeName();
attrValues[j] = attr.getNodeValue();
// Do your stuff here
//System.out.println("Found attribute: " + attrName + "
with value: " + attrValue);
}
}
Intent myIntent = new
Intent(CameraTestActivity.this,DisplayActivity.class);
myIntent.putExtra("myattrnames",attrNames);
myIntent.putExtra("myattrvalues",attrValues);
myIntent.putExtra("myname",name);
myIntent.putExtra("mydob",dob);
myIntent.putExtra("myno",no);
myIntent.putExtra("parse",str);
startActivity(myIntent);

}
};

// Mimic continuous auto-focusing


AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
autoFocusHandler.postDelayed(doAutoFocus, 1000);
}
};
}

32

33

APPENDICE-III
PARSE MODULE
package com.sinch.messagingtutorial.app;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.annotation.TargetApi;
android.app.Activity;
android.app.Notification;
android.app.NotificationManager;
android.app.PendingIntent;
android.content.ComponentName;
android.content.Intent;
android.content.ServiceConnection;
android.os.Build;
android.os.Bundle;
android.os.IBinder;
android.view.View;
android.widget.EditText;
android.widget.ListView;
android.widget.Toast;

import com.parse.FindCallback;
import com.parse.ParseObject;
import com.parse.ParseQuery;

34

import
import
import
import
import
import
import
import

com.parse.ParseUser;
com.sinch.android.rtc.PushPair;
com.sinch.android.rtc.messaging.Message;
com.sinch.android.rtc.messaging.MessageClient;
com.sinch.android.rtc.messaging.MessageClientListener;
com.sinch.android.rtc.messaging.MessageDeliveryInfo;
com.sinch.android.rtc.messaging.MessageFailureInfo;
com.sinch.android.rtc.messaging.WritableMessage;

import java.util.Arrays;
import java.util.List;
public class MessagingActivity extends Activity {
private String recipientId;
private EditText messageBodyField;
private String messageBody;
private MessageService.MessageServiceInterface messageService;
private MessageAdapter messageAdapter;
private ListView messagesList;
private String currentUserId;
private ServiceConnection serviceConnection = new MyServiceConnection();
private MessageClientListener messageClientListener = new
MyMessageClientListener();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.messaging);
bindService(new Intent(this, MessageService.class), serviceConnection,
BIND_AUTO_CREATE);
Intent intent = getIntent();
recipientId = intent.getStringExtra("RECIPIENT_ID");
currentUserId = ParseUser.getCurrentUser().getObjectId();
messagesList = (ListView) findViewById(R.id.listMessages);
messageAdapter = new MessageAdapter(this);
messagesList.setAdapter(messageAdapter);
populateMessageHistory();
messageBodyField = (EditText) findViewById(R.id.messageBodyField);
findViewById(R.id.sendButton).setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
sendMessage();
}
});
}
//get previous messages from parse & display
private void populateMessageHistory() {
String[] userIds = {currentUserId, recipientId};
ParseQuery<ParseObject> query = ParseQuery.getQuery("ParseMessage");
query.whereContainedIn("senderId", Arrays.asList(userIds));
query.whereContainedIn("recipientId", Arrays.asList(userIds));
query.orderByAscending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> messageList,
com.parse.ParseException e) {

35

if (e == null) {
for (int i = 0; i < messageList.size(); i++) {
WritableMessage message = new
WritableMessage(messageList.get(i).get("recipientId").toString(),
messageList.get(i).get("messageText").toString());
if
(messageList.get(i).get("senderId").toString().equals(currentUserId)) {
messageAdapter.addMessage(message,
MessageAdapter.DIRECTION_OUTGOING);
} else {
messageAdapter.addMessage(message,
MessageAdapter.DIRECTION_INCOMING);
}
}
}
}
});
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private void sendMessage() {
messageBody = messageBodyField.getText().toString();
if (messageBody.isEmpty()) {
Toast.makeText(this, "Please enter a message",
Toast.LENGTH_LONG).show();
return;
}
messageService.sendMessage(recipientId, messageBody);
messageBodyField.setText("");
}
@Override
public void onDestroy() {
messageService.removeMessageClientListener(messageClientListener);
unbindService(serviceConnection);
super.onDestroy();
}
private class MyServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName componentName, IBinder
iBinder) {
messageService = (MessageService.MessageServiceInterface) iBinder;
messageService.addMessageClientListener(messageClientListener);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
messageService = null;
}
}
private class MyMessageClientListener implements MessageClientListener {
@Override
public void onMessageFailed(MessageClient client, Message message,
MessageFailureInfo failureInfo) {
Toast.makeText(MessagingActivity.this, "Message failed to send.",
Toast.LENGTH_LONG).show();
}
@Override
public void onIncomingMessage(MessageClient client, Message message) {
if (message.getSenderId().equals(recipientId)) {

36

WritableMessage writableMessage = new


WritableMessage(message.getRecipientIds().get(0), message.getTextBody());
messageAdapter.addMessage(writableMessage,
MessageAdapter.DIRECTION_INCOMING);
Notify(recipientId,message.getTextBody());
}
}
@Override
public void onMessageSent(MessageClient client, Message message, String
recipientId) {
final WritableMessage writableMessage = new
WritableMessage(message.getRecipientIds().get(0), message.getTextBody());
//only add message to parse database if it doesn't already exist
there
ParseQuery<ParseObject> query =
ParseQuery.getQuery("ParseMessage");
query.whereEqualTo("sinchId", message.getMessageId());
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> messageList,
com.parse.ParseException e) {
if (e == null) {
if (messageList.size() == 0) {
ParseObject parseMessage = new
ParseObject("ParseMessage");
parseMessage.put("senderId", currentUserId);
parseMessage.put("recipientId",
writableMessage.getRecipientIds().get(0));
parseMessage.put("messageText",
writableMessage.getTextBody());
parseMessage.put("sinchId",
writableMessage.getMessageId());
parseMessage.saveInBackground();
messageAdapter.addMessage(writableMessage,
MessageAdapter.DIRECTION_OUTGOING);
}
}
}
});
}
@Override
public void onMessageDelivered(MessageClient client,
MessageDeliveryInfo deliveryInfo) {}
@Override
public void onShouldSendPushData(MessageClient client, Message message,
List<PushPair> pushPairs) {}
}
@SuppressWarnings("deprecation")
private void Notify(String notificationTitle, String notificationMessage) {
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
@SuppressWarnings("deprecation")
Notification notification = new Notification(R.drawable.ic_launcher,
"New Message", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MessagingActivity.class);

37

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,


notificationIntent, 0);
notification.setLatestEventInfo(MessagingActivity.this,
notificationTitle,
notificationMessage, pendingIntent);
notificationManager.notify(9999, notification);
}
}

public class MyApplication extends Application {


@Override
public void onCreate() {
super.onCreate();
//Parse.initialize(this, "app-id", "client-key");
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Parse.initialize(this,
"PIMI3CC3gw8UfOFXKxqRgPaxbfeKArNZSuic64bF","1yfvMjGpUJObIeqoIvmgV6UWaSEdm0nHI3v
8lmhs");
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the
broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
}

38

39

=
40

APPENDICE-IV
SINCH MODULE
package com.sinch.messagingtutorial.app;
import
import
import
import
import
import
import
import

android.app.Notification;
android.app.NotificationManager;
android.app.PendingIntent;
android.app.Service;
android.content.Intent;
android.os.Binder;
android.os.IBinder;
android.support.v4.content.LocalBroadcastManager;

import
import
import
import
import
import
import
import
import

com.parse.ParseUser;
com.sinch.android.rtc.ClientRegistration;
com.sinch.android.rtc.Sinch;
com.sinch.android.rtc.SinchClient;
com.sinch.android.rtc.SinchClientListener;
com.sinch.android.rtc.SinchError;
com.sinch.android.rtc.messaging.MessageClient;
com.sinch.android.rtc.messaging.MessageClientListener;
com.sinch.android.rtc.messaging.WritableMessage;

public class
MessageService extends Service implements SinchClientListener {
private static final String APP_KEY = "a5a9d519-418e-4edc-8d17f740e78ddb44";
private static final String APP_SECRET = "FFtAhu8y+USk8J4hJvwEGw==";
private static final String ENVIRONMENT = "sandbox.sinch.com";
private final MessageServiceInterface serviceInterface = new
MessageServiceInterface();
private SinchClient sinchClient = null;
private MessageClient messageClient = null;
private String currentUserId;
private LocalBroadcastManager broadcaster;
private Intent broadcastIntent = new
Intent("com.sinch.messagingtutorial.app.ListUsersActivity");
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
currentUserId = ParseUser.getCurrentUser().getObjectId();
if (currentUserId != null && !isSinchClientStarted()) {
startSinchClient(currentUserId);
}
broadcaster = LocalBroadcastManager.getInstance(this);
return super.onStartCommand(intent, flags, startId);
}
public void startSinchClient(String username) {
sinchClient =
Sinch.getSinchClientBuilder().context(this).userId(username).applicationKey(APP
_KEY)
.applicationSecret(APP_SECRET).environmentHost(ENVIRONMENT).build();

41

sinchClient.addSinchClientListener(this);
sinchClient.setSupportMessaging(true);
sinchClient.setSupportActiveConnectionInBackground(true);
sinchClient.checkManifest();
sinchClient.start();
}
private boolean isSinchClientStarted() {
return sinchClient != null && sinchClient.isStarted();
}
@Override
public void onClientFailed(SinchClient client, SinchError error) {
broadcastIntent.putExtra("success", false);
broadcaster.sendBroadcast(broadcastIntent);
sinchClient = null;
}
@Override
public void onClientStarted(SinchClient client) {
broadcastIntent.putExtra("success", true);
broadcaster.sendBroadcast(broadcastIntent);
client.startListeningOnActiveConnection();
messageClient = client.getMessageClient();
}
@Override
public void onClientStopped(SinchClient client) {
sinchClient = null;
}
@Override
public IBinder onBind(Intent intent) {
return serviceInterface;
}
@Override
public void onLogMessage(int level, String area, String message) {
}
@Override
public void onRegistrationCredentialsRequired(SinchClient client,
ClientRegistration clientRegistration) {
}
public void sendMessage(String recipientUserId, String textBody) {
if (messageClient != null) {
WritableMessage message = new WritableMessage(recipientUserId,
textBody);
messageClient.send(message);
}
}
public void addMessageClientListener(MessageClientListener listener) {
if (messageClient != null) {
messageClient.addMessageClientListener(listener);
}
}
public void removeMessageClientListener(MessageClientListener listener) {

42

if (messageClient != null) {
messageClient.removeMessageClientListener(listener);
}
}
@Override
public void onDestroy() {
sinchClient.stopListeningOnActiveConnection();
sinchClient.terminate();
}
public class MessageServiceInterface extends Binder {
public void sendMessage(String recipientUserId, String textBody) {
MessageService.this.sendMessage(recipientUserId, textBody);
}
public void addMessageClientListener(MessageClientListener listener) {
MessageService.this.addMessageClientListener(listener);
}
public void removeMessageClientListener(MessageClientListener listener)
{
MessageService.this.removeMessageClientListener(listener);
}
public boolean isSinchClientStarted() {
return MessageService.this.isSinchClientStarted();
}
}
}

43

44

45