Development and remote installation of Java service for the Android Devices
Development and remote installation of Java service for the Android Devices
Free Online Articles Directory
Why Submit Articles?
Top Authors
Top Articles
FAQ
AB Answers
Publish Article
0 && $.browser.msie ) {
var ie_version = parseInt($.browser.version);
if(ie_version Hello Guest
Login
Register
Hello
My Home
Sign Out
Email
Password
Remember me?
Lost Password?
Home Page > Computers > Programming > Development and remote installation of Java service for the Android Devices
Development and remote installation of Java service for the Android Devices
Edit Article |
Posted: Aug 14, 2009 |Comments: 0
| Views: 576
|
]]>
Ask a question
Ask our experts your Programming related questions here…200 Characters left
Related Questions
Since installing windows 7 I have no sound it is saying no audio output device is installed do you know what I can do to fix this
I could not finished download any android apps & game into my iped apad 7″ ( version 1.6 ). Once clicked install on any program, it shown “start downloading” but never complete. Why…
I have caller id service from my telco… Is there a device that I can hook up to my telephone line that will perform reverse number look up at the same time that the caller id is displayed?
My plastic cover of Samsung gt-s5230 which located on the screen broke and my touch screen now don’t work! Where can I buy a new plastic cover? *Without going it to service* I can install it by myself
Copy to clipboard
Development and remote installation of Java service for the Android Devices
By: Apriorit
About the Author
Apriorit is an Ukrainian software development company.
Apriorit develops its own products as well as provide offshore development and QA services in the areas of advanced system programming, driver development, software for devices.
One of the key values of Apriorit’s specialists is knowledge generation and sharing of experience.
Learn more about Apriorit and its experience at Apriorit Official site
(ArticlesBase SC #1127620)
Article Source: – Development and remote installation of Java service for the Android Devices
Written by:
Igor Darkov, Software Developer of Device Team, Apriorit Inc.
In this article I’ve described:
How to develop simple Java service for the Android Devices; How to communicate with a service from the other processes and a remote PC; How to install and start the service remotely from the PC. 1. Java Service Development for the Android Devices
Services are long running background processes provided by Android. They could be used for background tasks execution. Tasks can be different: background calculations, backup procedures, internet communications, etc. Services can be started on the system requests and they can communicate with other processes using the Android IPC channels technology. The Android system can control the service lifecycle depending on the client requests, memory and CPU usage. Note that the service has lower priority than any process which is visible for the user.
Let’s develop the simple example service. It will show scheduled and requested notifications to user. Service should be managed using the service request, communicated from the simple Android Activity and from the PC.
First we need to install and prepare environment:
Download and install latest Android SDK from the official web site (http://developer.android.com); Download and install Eclipse IDE (http://www.eclipse.org/downloads/); Also we’ll need to install Android Development Tools (ADT) plug-in for Eclipse.
After the environment is prepared we can create Eclipse Android project. It will include sources, resources, generated files and the Android manifest.
1.1 Service class development
First of all we need to implement service class. It should be inherited from the android.app.Service (http://developer.android.com/reference/android/app/Service.html) base class. Each service class must have the corresponding <service> declaration in its package’s manifest. Manifest declaration will be described later. Services, like the other application objects, run in the main thread of their hosting process. If you need to do some intensive work, you should do it in another thread.
In the service class we should implement abstract method onBind. Also we override some other methods:
onCreate(). It is called by the system when the service is created at the first time. Usually this method is used to initialize service resources. In our case the binder, task and timer objects are created. Also notification is send to the user and to the system log: public void onCreate() { super.onCreate(); Log.d(LOG_TAG, “Creating service”); showNotification(“Creating NotifyService”); binder = new NotifyServiceBinder(handler, notificator); task = new NotifyTask(handler, notificator); timer = new Timer(); } onStart(Intent intent, int startId). It is called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it requires and the unique integer token representing the start request. We can launch background threads, schedule tasks and perform other startup operations. public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.d(LOG_TAG, “Starting service”); showNotification(“Starting NotifyService”); timer.scheduleAtFixedRate(task, Calendar.getInstance().getTime(), 30000); } onDestroy(). It is called by the system to notify a Service that it is no longer used and is being removed. Here we should perform all operations before service is stopped. In our case we will stop all scheduled timer tasks. public void onDestroy() { super.onDestroy(); Log.d(LOG_TAG, “Stopping service”); showNotification(“Stopping NotifyService”); timer.cancel(); } onBind(Intent intent). It will return the communication channel to the service. IBinder is the special base interface for a remotable object, the core part of a lightweight remote procedure call mechanism. This mechanism is designed for the high performance of in-process and cross-process calls. This interface describes the abstract protocol for interacting with a remotable object. The IBinder implementation will be described below. public IBinder onBind(Intent intent) { Log.d(LOG_TAG, “Binding service”); return binder; }
To send system log output we can use static methods of the android.util.Log class (http://developer.android.com/reference/android/util/Log.html). To browse system logs on PC you can use ADB utility command: adb logcat.
The notification feature is implemented in our service as the special runnable object. It could be used from the other threads and processes. The service class has method showNotification, which can display message to user using the Toast.makeText call. The runnable object also uses it:
public class NotificationRunnable implements Runnable { private String message = null; public void run() { if (null != message) { showNotification(message); } } public void setMessage(String message) { this.message = message; } }
Code will be executed in the service thread. To execute runnable method we can use the special object android.os.Handler. There are two main uses for the Handler: to schedule messages and runnables to be executed as some point in the future; and to place an action to be performed on a different thread than your own. Each Handler instance is associated with a single thread and that thread’s message queue. To show notification we should set message and call post() method of the Handler’s object.
1.2 IPC Service
Each application runs in its own process. Sometimes you need to pass objects between processes and call some service methods. These operations can be performed using IPC. On the Android platform, one process can not normally access the memory of another process. So they have to decompose their objects into primitives that can be understood by the operating system , and “marshall” the object across that boundary for developer.
The AIDL IPC mechanism is used in Android devices. It is interface-based, similar to COM or Corba, but is lighter . It uses a proxy class to pass values between the client and the implementation.
AIDL (Android Interface Definition Language) is an IDL language used to generate code that enables two processes on an Android-powered device to communicate using IPC. If you have the code in one process (for example, in Activity) that needs to call methods of the object in another process (for example, Service), you can use AIDL to generate code to marshall the parameters.
Service interface example showed below supports only one sendNotification call:
interface INotifyService { void sendNotification(String message); }
The IBinder interface for a remotable object is used by clients to perform IPC. Client can communicate with the service by calling Context’s bindService(). The IBinder implementation could be retrieved from the onBind method. The INotifyService interface implementation is based on the android.os.Binder class (http://developer.android.com/reference/android/os/Binder.html):
public class NotifyServiceBinder extends Binder implements INotifyService { private Handler handler = null; private NotificationRunnable notificator = null; public NotifyServiceBinder(Handler handler, NotificationRunnable notificator) { this.handler = handler; this.notificator = notificator; } public void sendNotification(String message) { if (null != notificator) { notificator.setMessage(message); handler.post(notificator); } } public IBinder asBinder() { return this; } }
As it was described above, the notifications could be send using the Handler object’s post() method call. The NotificaionRunnable object is passed as the method’s parameter.
On the client side we can request IBinder object and work with it as with the INotifyService interface. To connect to the service the android.content.ServiceConnection interface implementation can be used. Two methods should be defined: onServiceConnected, onServiceDisconnected:
ServiceConnection conn = null; … conn = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { Log.d(“NotifyTest”, “onServiceConnected”); INotifyService s = (INotifyService) service; try { s.sendNotification(“Hello”); } catch (RemoteException ex) { Log.d(“NotifyTest”, “Cannot send notification”, ex); } } public void onServiceDisconnected(ComponentName name) { } };
The bindService method can be called from the client Activity context to connect to the service:
Context.bindService(new Intent(this, NotifyService.class), conn, Context.BIND_AUTO_CREATE);
The unbindService method can be called from the client Activity context to disconnect from the service:
Context.unbindService(conn); 1.3 Remote service control
Broadcasts are the way applications and system components can communicate. Also we can use broadcasts to control service from the PC. The messages are sent as Intents, and the system handles dispatching them, including starting receivers.
Intents can be broadcasted to BroadcastReceivers, allowing messaging between applications. By registering a BroadcastReceiver in application’s AndroidManifest.xml (using <receiver> tag) you can have your application’s receiver class started and called whenever someone sends you a broadcast. Activity Manager uses the IntentFilters, applications register to figure out which program should be used for a given broadcast.
Let’s develop the receiver that will start and stop notify service on request. The base class android.content.BroadcastReceiver should be used for these purposes (http://developer.android.com/reference/android/content/BroadcastReceiver.html):
public class ServiceBroadcastReceiver extends BroadcastReceiver { … private static String START_ACTION = “NotifyServiceStart”; private static String STOP_ACTION = “NotifyServiceStop”; … public void onReceive(Context context, Intent intent) { … String action = intent.getAction(); if (START_ACTION.equalsIgnoreCase(action)) { context.startService(new Intent(context, NotifyService.class)); } else if (STOP_ACTION.equalsIgnoreCase(action)) { context.stopService(new Intent(context, NotifyService.class)); } } }
To send broadcast from the client application we use the Context.sendBroadcast call. I will describe how to use receiver and send broadcasts from the PC in chapter 2.
1.4 Android Manifest
Every application must have an AndroidManifest.xml file in its root directory. The manifest contains essential information about the application to the Android system, the system must have this information before it can run any of the application’s code. The core components of an application (its activities, services, and broadcast receivers) are activated by intents. An intent is a bundle of information (an Intent object) describing a desired action — including the data to be acted upon, the category of component that should perform the action, and other pertinent instructions. Android locates an appropriate component to respond to the intent, starts the new instance of the component if one is needed, and passes it to the Intent object.
We should describe 2 components for our service:
NotifyService class is described in the <service> tag. It will not start on intent. So the intent filtering is not needed. ServiceBroadcastReceived class is described in the <receiver> tag. For the broadcast receiver the intent filter is used to select system events: <application android:icon=”@drawable/icon” android:label=”@string/app_name”> … <service android:enabled=”true” android:name=”.NotifyService” android:exported=”true”> </service> <receiver android:name=”ServiceBroadcastReceiver”> <intent-filter> <action android:name=”NotifyServiceStart”></action> <action android:name=”NotifyServiceStop”></action> </intent-filter> </receiver> … 2. Java service remote installation and start 2.1 Service installation
Services like the other applications for the Android platform can be installed from the special package with the .apk extension. Android package contains all required binary files and the manifest.
Before installing the service from the PC we should enable the USB Debugging option in the device Settings-Applications-Development menu and then connect device to PC via the USB.
On the PC side we will use the ADB utility which is available in the Android SDK tools directory. The ADB utility supports several optional command-line arguments that provide powerful features, such as copying files to and from the device. The shell command-line argument lets you connect to the phone itself and issue rudimentary shell commands.
We will use several commands:
Remote shell command execution: adb shell <command> <arguments> File send operation: adb push <local path> <remote path> Package installation operation: adb install <package>.apk
I’ll describe the package installation process in details. It consists of several steps which are performed by the ADB utility install command:
First of all the .apk package file should be copied to the device. The ADB utility connects to the device and has limited “shell” user privileges. So almost all file system directories are write-protected for it. The /data/local/tmp directory is used as the temporary storage for package files. To copy package to the device use the command: adb push NotifyService.apk /data/local/tmp Package installation. ADB utility uses special shell command to perform this operation. The “pm” (Package Manager?) utility is present on the Android devices. It supports several command line parameters which are described in the Appendix I. To install the package by yourself execute the remote shell command: adb shell pm install /data/local/tmp/NotifyService.apk Cleanup. After the package is installed, ADB removes the temporary file stored in /data/local/tmp folder using the “rm” utility: adb shell rm /data/local/tmp/NotifyService.apk. To uninstall package use the “pm” utility: adb shell pm uninstall <package> 2.2 Remote service control
To be able to start and stop the NotifyService from the PC we can use the “am” (Activity Manager?) utility which is present on the Android device. The command line parameters are described in the Appendix II. The “am” utility can send system broadcast intents. Our service has the broadcast receiver which will be launched by the system request.
To start NotifyService we can execute remote shell command:
adb shell am broadcast –a NotifyServiceStart
To stop the NotifyService we can execute remote shell command:
adb shell am broadcast –a NotifyServiceStop
Note, that the NotifyServiceStart and NotifyServiceStop intents were described in the manifest file inside the <receiver> … <intent-filter> tag. Other requests will not start the receiver.
Appendix I. PM Usage (from Android console) pm [list|path|install|uninstall] pm list packages [-f] pm list permission-groups pm list permissions [-g] [-f] [-d] [-u] [GROUP] pm path PACKAGE pm install [-l] [-r] PATH pm uninstall [-k] PACKAGE The list packages command prints all packages. Use the -f option to see their associated file. The list permission-groups command prints all known permission groups. The list permissions command prints all known permissions, optionally only those in GROUP. Use the -g option to organize by group. Use the -f option to print all information. Use the -s option for a short summary. Use the -d option to only list dangerous permissions. Use the -u option to list only the permissions users will see. The path command prints the path to the .apk of a package. The install command installs a package to the system. Use the -l option to install the package with FORWARD_LOCK. Use the -r option to reinstall an exisiting app, keeping its data. The uninstall command removes a package from the system. Use the -k option to keep the data and cache directories around after the package removal. Appendix II. AM Usage (from Android console) am [start|broadcast|instrument] am start -D INTENT am broadcast INTENT am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>] [-w] <COMPONENT> INTENT is described with: [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-c <CATEGORY> [-c <CATEGORY>] …] [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...] [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...] [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...] [-n <COMPONENT>] [-f <FLAGS>] [<URI>] Resources used: Android Installation Guide.
http://developer.android.com/sdk/1.5_r2/installing.html
Android Developer reference.
http://developer.android.com/reference/classes.html
Jesse Burns. Developing Secure Mobile Applications for Android.
https://www.isecpartners.com/files/iSEC_Securing_Android_Apps.pdf
Designing a Remote Interface Using AIDL
http://developer.android.com/guide/developing/tools/aidl.html
Retrieved from “http://www.articlesbase.com/programming-articles/development-and-remote-installation-of-java-service-for-the-android-devices-1127620.html”
(ArticlesBase SC #1127620)
Apriorit -
About the Author:
Apriorit is an Ukrainian software development company.
Apriorit develops its own products as well as provide offshore development and QA services in the areas of advanced system programming, driver development, software for devices.
One of the key values of Apriorit’s specialists is knowledge generation and sharing of experience.
Learn more about Apriorit and its experience at Apriorit Official site
]]>
Rate this Article
vote(s)
0 vote(s)
Feedback
RSS
Print
Email
Re-Publish
Source: http://www.articlesbase.com/programming-articles/development-and-remote-installation-of-java-service-for-the-android-devices-1127620.html
Article Tags:
android development, simple java service for the android, communicate with a service, remote service installation
Latest Programming Articles
More from Apriorit
The Google Android Demo
Learn about the new Google mobile phone operating system through this demo. (06:24)
Dell Mini 3i Smartphone Review
The smartphone goes on sale from China Mobile in December (01:17)
Microsoft Expressions Web – Dynamic Site Setup on a Web Hosting Service
Learn the process of setting up the Dynamic Site on a Web Hosting Service using the Microsoft ASP.NET Development Server (02:04)
Do I Need a Wed Developer or a Web Designer?
GoldenWebDesign.com – Learn how to properly assess if you require the services of a web developer or a web designer, and who to turn to for your web needs. (00:34)
Virtual Decorator – Architectural Visualization Services Sample Presentation
Video screen capture from a real time model of a retirement / nursing home development. (02:21)
How to Send Email from a PHP Script ?
Firstly, what Is PHP? PHP stands for Hypertext Preprocessor and is a server-side language. This way that the manuscript is run on your web server, not on the exploiter browser, so you do not demand to stress approx compatibility issues. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becomming one of the carcass popular scripting languages on the internet, so how can we send email from a PHP Script ? Look our help in the article body …
By:
Hermannl
Computers>
Programmingl
Nov 18, 2010
Hire Dedicated Magento Developer for Professional PSD-To-Magento Solutions
Hiring dedicated Magento developer is a right way to get professional PSD-to-Magento conversion solution. This article is framed to cover the benefits of outsourcing aid of web developer.
By:
Devashish Kumarl
Computers>
Programmingl
Nov 18, 2010
Advertise In Your Own Website
Forget about unnecessary huge spending on advertising and promotions for your business. There definitely is a market on the Internet. No other advertising and promotions office can guarantee you such an amazingly immense leverage. Advertise in your own website now.
By:
Angela Paulal
Computers>
Programmingl
Nov 18, 2010
Outsourced Software Development to India for Reaping the Maximum Benefits
All your necessary software programs and applications can be designed and developed at very affordable rates just by getting the projects done at an outsourced software development service facility.
By:
Arun Kumarl
Computers>
Programmingl
Nov 18, 2010
Is The Free Registry Cleaner My Anti-Virus Company Is Offering Any Good?
I’ve seen where a couple of anti-virus software programs are “giving” a “free” registry scan and repair to their users. The ones I know of are good legitimate companies with good to excellent virus programs. Now all anti-virus system are not good. And particularly the most common and oldest name is considered very poor by a large segment of the computer repair world.
By:
John Johnsonl
Computers>
Programmingl
Nov 17, 2010
Basics of Software Development in Relation to Offshore Product Development
The trend to outsource software development activities is growing very fast among contemporary businesses. The reason behind the rising popularity of outsourcing is due to the trouble-free availability of competent programmers and computer engineers at low costs. Offshore product development can assist businesses in yielding a big margin in profits on a low-scale investment.
By:
Harkirat Singh Bedil
Computers>
Programmingl
Nov 17, 2010
ASP Net: The Programmer’ key to effective and creative Application Development
The flexibility found in the ASP.NET programming is worth mentioning due to its language independency paradigm. ASP NET application development process follows a set of authentication schemes and default authorization policy that covers the entire user defined codes that can be easily interchanged as per the demand.
By:
Harkirat Singh Bedil
Computers>
Programmingl
Nov 17, 2010
Outsource Software Development to India to Get Quality Services at Cost Effective Prices
In these advanced epochs where Information Technology is ruling the roost, the most sought after bunch of folks are considering custom software development using the services of expert asp.net programmers and J2EE application development professionals. In such milieu, one niche industry segment which is fast emerging as a hot favorite is Offshore Software Development India.
By:
Harkirat Singh Bedil
Computers>
Programmingl
Nov 17, 2010
Testing Strategies for the Software Virtualization Systems
In this article, we will examine the specific of testing of the software virtualization systems. We will touch upon the following questions: * test environment configuration; * testing types; * nuances of each of testing types for the virtualization systems. So, we will examine those important things that should be taken into account when thinking over the testing strategy of the software virtualization system.
By:
Aprioritl
Computers>
Softwarel
Oct 04, 2010
Exchange Server: Express Configuration for Testing
This article can be useful for those testers who configure their test environment themselves without the help of the system administrator. The aim of the article is to present a step-by-step description of the installation and configuration of the domain controller, Exchange Server, and MS Outlook with two accounts for the testing purposes.
By:
Aprioritl
Computers>
Softwarel
Oct 04, 2010
User mode transport of the library via virtual channels
In this article, we provide the library which can be used in client – server applications to cover transport layer using virtual channels. Also we attached sample add-in project (client side) and sample server application.
By:
Aprioritl
Computers>
Programmingl
Jun 11, 2010
Generating PDF reports using nfop
Sometimes we need to create representative PDF reports or documents within our program. In this case, developers face nontrivial problems – for example creating the table of contents (using internal or external links), bookmark trees, picture galleries, etc. This article will help you to examine main features of XSL schemes.
By:
Aprioritl
Computers>
Programmingl
Jun 09, 2010
lViews: 113
How to test virtual desktop acceleration in the LAN and WAN configurations
This article is devoted to the testing of programs that use virtual desktop acceleration to improve performance. Here we will consider features of virtualization, testing scenarios, some useful tools and tips, and also will give examples of real test cases.
By:
Aprioritl
Computers>
Programmingl
Jun 04, 2010
Windows2Linux Porting
Porting an application from one platform (Windows) to another (Linux) is an interesting topic. First, knowledge of several platforms and writing the code for them is a good experience for every developer. Secondly, writing an application for different platforms makes it widespread and needed by many. So, I would like to share my impressions concerning this process. This article is intended for everybody who wants to write a cross-platform application.
By:
Aprioritl
Computers>
Programmingl
May 18, 2010
Port Monitor: How to receive the number of document copies during the printing
In this article, we will examine a problem of receiving the correct value of the dmCopies variable in the DEVMODE structure while printing from Microsoft Word 2003. This can be useful for the case of writing a program that controls printing (to printers, as well as to files).
By:
Aprioritl
Computers>
Programmingl
May 18, 2010
The testing report as the powerful tool of the optimization of the software development process
If you prepared the testing reports without making the preliminary analysis of the findings before, please start doing it. The correctly prepared report on the results of testing is a powerful tool for the optimization of the software development process. That is why let’s pay special attention to this process. This article includes practical recommendations concerning the preparation of different types of testing reports and their ready examples.
By:
Aprioritl
Computersl
May 18, 2010
Add new Comment
Your Name: *
Your Email:
Comment Body: *
Verification code:*
* Required fields
Submit
Your Articles Here
It’s Free and easy
Sign Up Today
Author Navigation
My Home
Publish Article
View/Edit Articles
View/Edit Q&A
Edit your Account
Manage Authors
Statistics Page
Personal RSS Builder
My Home
Edit your Account
Update Profile
View/Edit Q&A
Publish Article
Author Box
Apriorit has 20 articles online
Contact Author
Subscribe to RSS
Print article
Send to friend
Re-Publish article
Articles Categories
All Categories
Advertising
Arts & Entertainment
Automotive
Beauty
Business
Careers
Computers
Education
Finance
Food and Beverage
Health
Hobbies
Home and Family
Home Improvement
Internet
Law
Marketing
News and Society
Relationships
Self Improvement
Shopping
Spirituality
Sports and Fitness
Technology
Travel
Writing
Computers
Computer Forensics
Computer Games
Data Recovery
Databases
E-Learning
File Types
Hardware
Information Technology
Intra-net
Laptops
Networks
Operating Systems
Programming
Security
Software
]]>
Need Help?
Contact Us
FAQ
Submit Articles
Editorial Guidelines
Blog
Site Links
Recent Articles
Top Authors
Top Articles
Find Articles
Site Map
Webmasters
RSS Builder
RSS
Link to Us
Business Info
Advertising
Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2010 Free Articles by ArticlesBase.com, All rights reserved.
Apriorit is an Ukrainian software development company.
Apriorit develops its own products as well as provide offshore development and QA services in the areas of advanced system programming, driver development, software for devices.
One of the key values of Apriorit’s specialists is knowledge generation and sharing of experience.
Learn more about Apriorit and its experience at Apriorit Official site
Archos 7 8GB Home Tablet with Android (Black)
- 8GB capacity for about 4000 songs, 80,000 photos, or seven full-length movies
- Seven hours of video or 42 hours of audio on a single charge
- 7-inch TFT LCD touchscreen with 800×480 pixel resolution, 16m colors
- Supports H.264/MPEG-4/Real video codecs in AVI, MP4, MKV, MOV, and FLV file formats; MP3, WMA, WAV, APE, OGG, FLAC
- One-year limited warranty
ARCHOS now introduces a new large-screen Android-based tablet, the ARCHOS 7 home tablet. This new product is specially designed to enhance the digital lifestyle in the home. The ARCHOS 7 home tablet bridges the gap between the smartphone and the desktop PC to provide constant access to the web, customization through Android Apps, and multimedia content – all in a large-screen format. This new device testifies to ARCHOS’ strategy of offering innovative electronic products with extremely competiti
Rating: (out of reviews)
List Price: $ 199.99
Price: $ 182.95









