Advertisement
Guest User

Media service android bug

a guest
Mar 23rd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package com.example.test;
  2.  
  3. import android.app.NotificationManager;
  4. import android.app.PendingIntent;
  5. import android.app.Service;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.os.IBinder;
  9. import android.support.v4.app.NotificationCompat;
  10. import android.util.Log;
  11.  
  12. public class MediaService extends Service
  13. {
  14.     private static final String TAG = "MediaService";
  15.  
  16.     private boolean mIsServiceBound;
  17.    
  18.     @Override
  19.     public void onCreate ()
  20.     {
  21.         super.onCreate();
  22.        
  23.         NotificationCompat.Builder builder = new NotificationCompat.Builder(this);  
  24.         builder.setSmallIcon(R.drawable.ic_launcher);
  25.         builder.setWhen(0);
  26.         builder.setCategory(null);
  27.         builder.setContentIntent(getPendingIntent(this));
  28.         builder.setContentTitle("Hello FlipaClip");
  29.         builder.setContentText("Hello FlipaClip");
  30.        
  31.         //NotificationManager nm = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
  32.         //nm.notify(1001, builder.build());
  33.         startForeground(1001, builder.build());
  34.     }
  35.    
  36.     @Override
  37.     public IBinder onBind (Intent intent)
  38.     {
  39.         Log.d(TAG,"onBind()");
  40.        
  41.         mIsServiceBound = true;
  42.        
  43.         return null;
  44.     }
  45.    
  46.     @Override
  47.     public void onRebind (Intent intent)
  48.     {
  49.         Log.d(TAG,"onRebind()");
  50.        
  51.         mIsServiceBound = true;
  52.        
  53.     }
  54.    
  55.     @Override
  56.     public boolean onUnbind (Intent intent)
  57.     {
  58.         Log.d(TAG,"onUnbind()");
  59.        
  60.         mIsServiceBound = false;
  61.        
  62.         return true;
  63.     }
  64.    
  65.     public PendingIntent getPendingIntent (Context context)
  66.     {
  67.         Intent showPlayer = new Intent(context, MainActivity.class);
  68.         showPlayer.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  69.         return PendingIntent.getActivity(
  70.                 context, 0, showPlayer, PendingIntent.FLAG_CANCEL_CURRENT);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement