Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.notify;
- 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.os.IBinder;
- import android.telephony.PhoneStateListener;
- import android.telephony.TelephonyManager;
- import android.widget.Toast;
- public class NotifyService extends Service
- {
- private static final int HELLO_ID = 1;
- private TelephonyManager tlfMan;
- private PhoneStateListener phStateListener = new PhoneStateListener() {
- String number;
- @Override
- public void onCallStateChanged(int state, String incomingNumber)
- {
- super.onCallStateChanged(state, incomingNumber);
- number = incomingNumber;
- if(state == TelephonyManager.CALL_STATE_RINGING)
- calling();
- }
- };
- private void calling()
- {
- String ns = Context.NOTIFICATION_SERVICE;
- NotificationManager myNotificationManager = (NotificationManager) getSystemService(ns);
- int icon = R.drawable.android_icon;
- CharSequence tickerText = "Hello, you've been notified! ";
- long when = System.currentTimeMillis();
- Notification ntf = new Notification(icon, tickerText, when);
- Context ctx = getApplicationContext();
- CharSequence contentTitle = "Missed call";
- CharSequence contentText = "From ";
- Intent notificationIntent = new Intent(this, ManageNumber.class);
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
- ntf.setLatestEventInfo(ctx, contentTitle, contentText, contentIntent);
- myNotificationManager.notify(HELLO_ID, ntf);
- }
- @Override
- public void onCreate()
- {
- super.onCreate();
- tlfMan = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
- tlfMan.listen(phStateListener, PhoneStateListener.LISTEN_CALL_STATE);
- }
- @Override
- public void onDestroy()
- {
- super.onDestroy();
- Toast.makeText(this, "Service.onDestroy()", Toast.LENGTH_LONG).show();
- tlfMan.listen(phStateListener, PhoneStateListener.LISTEN_NONE);
- }
- @Override
- public void onStart(Intent i, int startId)
- {
- super.onStart(i, startId);
- i.getStringExtra("number");
- Toast.makeText(this, "hei onStart()", Toast.LENGTH_LONG).show();
- }
- @Override
- public IBinder onBind(Intent i)
- {
- Toast.makeText(this, "Service.onBind()", Toast.LENGTH_LONG).show();
- return null;
- }
- }
Add Comment
Please, Sign In to add comment