Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.test;
- 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.support.v4.app.NotificationCompat;
- import android.util.Log;
- public class MediaService extends Service
- {
- private static final String TAG = "MediaService";
- private boolean mIsServiceBound;
- @Override
- public void onCreate ()
- {
- super.onCreate();
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
- builder.setSmallIcon(R.drawable.ic_launcher);
- builder.setWhen(0);
- builder.setCategory(null);
- builder.setContentIntent(getPendingIntent(this));
- builder.setContentTitle("Hello FlipaClip");
- builder.setContentText("Hello FlipaClip");
- //NotificationManager nm = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
- //nm.notify(1001, builder.build());
- startForeground(1001, builder.build());
- }
- @Override
- public IBinder onBind (Intent intent)
- {
- Log.d(TAG,"onBind()");
- mIsServiceBound = true;
- return null;
- }
- @Override
- public void onRebind (Intent intent)
- {
- Log.d(TAG,"onRebind()");
- mIsServiceBound = true;
- }
- @Override
- public boolean onUnbind (Intent intent)
- {
- Log.d(TAG,"onUnbind()");
- mIsServiceBound = false;
- return true;
- }
- public PendingIntent getPendingIntent (Context context)
- {
- Intent showPlayer = new Intent(context, MainActivity.class);
- showPlayer.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- return PendingIntent.getActivity(
- context, 0, showPlayer, PendingIntent.FLAG_CANCEL_CURRENT);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement