Transcript
Page 1: Beep Mini Project Report Finalized

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

i

Page 2: Beep Mini Project Report Finalized

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.

ii

Page 3: Beep Mini Project Report Finalized

TABLE OF CONTENTS

iii

Page 4: Beep Mini Project Report Finalized

CHAPTER NO. TITLE PAGE NO.

ABSTRACT V LIST OF FIGURES VI LIST OF ABBREVATIONS VII

1. INTRODUCTION 1 1.1 Introduction about Android Platform 1

1.2 Overview 1 1.3 Significance of Android 2 1.4 Architecture of Android Architecture 2 1.5 Applications of Android 3 1.6 Introduction of the project 4 1.7 Problem Statement 4 1.8 Objective of the project 4

2. LITERATURE REVIEW 5 2.1 SMS based alert system 5

3. SYSTEM ANALYSIS 6

3.1 Existing System 63.1.1 Disadvantage of Existing System 6

3.2 Proposed System 63.2.1 Advantage of ProposedSystem 6

3.3 Methodology and Development 6

4. SYSTEM SPECIFICATION 8 4.1 System Requirements 8

4.1.1 Hardware Requirements 84.1.2 Software Requirements 8

iv

Page 5: Beep Mini Project Report Finalized

TABLE OF CONTENTS 4.2 Software Specification 8

4.2.1 About JDK 8 4.2.2 JDK Implementing Languages 4 9

4.2.3 Architecture of JDK 10

5. SYSTEM IMPLEMENATION 15 5.1 List of Modules 15 5.2 Module Description 15

5.2.1 Login Module 15 5.2.2 QR Code Module 4 15

5.2.3 Parse Module 165.2.4 Sinch Module 16

6. CONCLUSION & FUTURE WORK APPENDICES 17

I Login Module 18 II QR Code Module 4 21 III Parse Module 27 IV Sinch Module 33

v

Page 6: Beep Mini Project Report Finalized

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.

vi

Page 7: Beep Mini Project Report Finalized

LIST OF FIGURES

SL. No. TITLE PAGE NO.

1.1 Architecture of Mobile Application 2

1.2 Java Virtual Machine 2

1.3 New portable Java Compile-Time

Environment

2

1.4 Functional relationship of JIT 2

1.5 Solaris JVM Functional Relationship 2

vii

Page 8: Beep Mini Project Report Finalized

LIST OF ABBREVIATION

IDE Integrated Development Environment

SDK Software Development Kit

ADT Android Development Tools

APK Android Package Kit

viii

Page 9: Beep Mini Project Report Finalized

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

1

Page 10: Beep Mini Project Report Finalized

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.

2

Page 11: Beep Mini Project Report Finalized

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.

3

Page 12: Beep Mini Project Report Finalized

Build on custom virtual machine android gives its users the addition usage and

application power, to initiate an interactive and efficient application and

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 we’ll develop it. Because it’s not our hero, It’s a silent guardian, a

watchful protector.

4

Page 13: Beep Mini Project Report Finalized

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 T-

Traffic, 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.

.

.

5

Page 14: Beep Mini Project Report Finalized

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

6

Page 15: Beep Mini Project Report Finalized

to increase the applications functionality. By using different plug-ins, Studio may also be used to develop application in other programming languages : Ada, 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.

7

Page 16: Beep Mini Project Report Finalized

CHAPTER 4

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.

8

Page 17: Beep Mini Project Report Finalized

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.

9

Page 18: Beep Mini Project Report Finalized

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.

10

Page 19: Beep Mini Project Report Finalized

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.

11

Page 20: Beep Mini Project Report Finalized

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

12

Page 21: Beep Mini Project Report Finalized

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

13

Page 22: Beep Mini Project Report Finalized

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

14

Page 23: Beep Mini Project Report Finalized

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.

15

Page 24: Beep Mini Project Report Finalized

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.

16

Page 25: Beep Mini Project Report Finalized

APPENDICE-I

LOGIN MODULE

package com.sinch.messagingtutorial.app;

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

import com.parse.LogInCallback;import com.parse.ParseUser;

public class LoginActivity extends Activity {

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

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

intent = new Intent(getApplicationContext(), ListUsersActivity.class); serviceIntent = new Intent(getApplicationContext(), MessageService.class);

17

Page 26: Beep Mini Project Report Finalized

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(); }}

18

Page 27: Beep Mini Project Report Finalized

19

Page 28: Beep Mini Project Report Finalized

APPENDICE-II

QR-CODE MODULE

package com.sinch.messagingtutorial.app;

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

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

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

import java.io.ByteArrayInputStream;import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;

20

Page 29: Beep Mini Project Report Finalized

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);

21

Page 30: Beep Mini Project Report Finalized

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);

22

Page 31: Beep Mini Project Report Finalized

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();

23

Page 32: Beep Mini Project Report Finalized

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); } };}

24

Page 33: Beep Mini Project Report Finalized

25

Page 34: Beep Mini Project Report Finalized

APPENDICE-III

PARSE MODULE

package com.sinch.messagingtutorial.app;

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

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

26

Page 35: Beep Mini Project Report Finalized

import com.parse.ParseUser;import com.sinch.android.rtc.PushPair;import com.sinch.android.rtc.messaging.Message;import com.sinch.android.rtc.messaging.MessageClient;import com.sinch.android.rtc.messaging.MessageClientListener;import com.sinch.android.rtc.messaging.MessageDeliveryInfo;import com.sinch.android.rtc.messaging.MessageFailureInfo;import 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) {

27

Page 36: Beep Mini Project Report Finalized

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)) {

28

Page 37: Beep Mini Project Report Finalized

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);

29

Page 38: Beep Mini Project Report Finalized

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","1yfvMjGpUJObIeqoIvmgV6UWaSEdm0nHI3v8lmhs"); 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); } } }); }}

30

Page 39: Beep Mini Project Report Finalized

31

Page 40: Beep Mini Project Report Finalized

=

32

Page 41: Beep Mini Project Report Finalized

APPENDICE-IV

SINCH MODULE

package com.sinch.messagingtutorial.app;

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

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

public class MessageService extends Service implements SinchClientListener {

private static final String APP_KEY = "a5a9d519-418e-4edc-8d17-f740e78ddb44"; 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();

33

Page 42: Beep Mini Project Report Finalized

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) {

34

Page 43: Beep Mini Project Report Finalized

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(); } }

}

35

Page 44: Beep Mini Project Report Finalized

36

Page 45: Beep Mini Project Report Finalized

37


Recommended