Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.greengobyte.ican;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.app.Service;
- import android.content.Context;
- import android.content.Intent;
- import android.content.pm.LauncherApps;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.drawable.BitmapDrawable;
- import android.graphics.drawable.Drawable;
- import android.graphics.drawable.Icon;
- import android.media.RingtoneManager;
- import android.os.Handler;
- import android.os.IBinder;
- import android.support.v4.app.NotificationCompat;
- import android.support.v4.app.NotificationManagerCompat;
- import android.support.v4.content.ContextCompat;
- import android.util.Log;
- import android.widget.Toast;
- import org.xmlpull.v1.XmlPullParser;
- import org.xmlpull.v1.XmlPullParserException;
- import org.xmlpull.v1.XmlPullParserFactory;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Timer;
- import java.util.TimerTask;
- import java.util.concurrent.TimeUnit;
- import me.leolin.shortcutbadger.ShortcutBadger;
- public class DoIT extends Service {
- final String LOG_TAG = "myLogs";
- NotificationManager nm;
- public static int notify = 120000;
- private Handler mHandler = new Handler();
- private Timer mTimer = null;
- private int day = 24;
- public void DoIT() {
- String[] doitArr = {
- "Ok",
- "Good",
- "Bad"
- };
- int max = doitArr.length;
- int min = 1;
- Random r = new Random();
- int itr = r.nextInt((max - min + 1));
- String tr = doitArr[itr];
- Intent intent = new Intent(this, NotifiWin.class);
- intent.putExtra("id", 1);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
- NotificationCompat.Builder nt = new NotificationCompat.Builder(this);
- nt.setContentTitle(getString(R.string.app_name))
- .setContentText(tr)
- .setSmallIcon(getApplicationInfo().icon)
- .setContentIntent(pendingIntent)
- .setWhen(System.currentTimeMillis())
- .setAutoCancel(true);
- nt.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
- nm.notify(1,nt.build());
- }
- public void onCreate() {
- super.onCreate();
- nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
- if (mTimer != null)
- mTimer.cancel();
- else
- mTimer = new Timer();
- mTimer.scheduleAtFixedRate(new TimeDisplay(), notify, notify);
- }
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- return super.onStartCommand(intent, flags, startId);
- //super.onStartCommand(intent, flags, startId);
- //return START_STICKY;
- }
- public void onDestroy() {
- super.onDestroy();
- }
- @Override
- public IBinder onBind(Intent intent) {
- //return null;
- // TODO: Return the communication channel to the service.
- throw new UnsupportedOperationException("Not yet implemented");
- }
- class TimeDisplay extends TimerTask {
- @Override
- public void run() {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- DoIT();
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement