- notifyservice.zip
- NotifyService
- NotifyService
- .classpath
- .project
- AndroidManifest.xml
- assets
- bin
- classes.dex
- com
- mycompany
- INotifyService$Stub$Proxy.class
- INotifyService$Stub.class
- INotifyService.aidl
- INotifyService.class
- NotifyService$NotificationRunnable.class
- NotifyService$NotifyServiceBinder.class
- NotifyService.class
- NotifyTask.class
- NotifyTest$1.class
- NotifyTest.class
- R$attr.class
- R$drawable.class
- R$layout.class
- R$string.class
- R.class
- ServiceBroadcastReceiver.class
- NotifyService.apk
- resources.ap_
- default.properties
- gen
- com
- mycompany
- res
- drawable
- icon.png
- layout
- values
- src
- com
- mycompany
|
package com.mycompany;
import java.util.Calendar;
import java.util.Timer;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class NotifyService extends Service
{
private final static String LOG_TAG = "NotifyService";
private Handler handler = new Handler();
private NotificationRunnable notificator = new NotificationRunnable();
private NotifyServiceBinder binder = null;
private NotifyTask task = null;
private Timer timer = null;
@Override
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();
}
@Override
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);
}
@Override
public void onDestroy()
{
super.onDestroy();
Log.d(LOG_TAG, "Stopping service");
showNotification("Stopping NotifyService");
timer.cancel();
}
@Override
public IBinder onBind(Intent intent)
{
Log.d(LOG_TAG, "Binding service");
return binder;
}
public void showNotification(String message)
{
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
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;
}
}
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);
}
}
@Override
public IBinder asBinder()
{
return this;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.
As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.
Our specialty is reverse engineering, we apply it for security testing and security-related projects.
A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.
Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.