package com.corner23.android.usb_otg_manager;

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.util.Log;

public class UnmountService extends Service {

	private Context mContext = this;
    
    private void handleCommand(Intent intent) {
    	boolean success = Main.doUnmount();
    	PendingIntent pi = PendingIntent.getService(mContext, 0, null, 0);
    	NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification();
        notification.icon = R.drawable.notification;
        notification.defaults = Notification.DEFAULT_ALL;
        
    	if (success) {
    		notificationManager.cancelAll();
            notification.setLatestEventInfo(mContext, getResources().getString(R.string.app_name), 
            		getResources().getString(R.string.str_unmounted_notify), pi);
    	} else {
            notification.setLatestEventInfo(mContext, getResources().getString(R.string.app_name), 
            		getResources().getString(R.string.str_err_unmount), pi);
    	}
    	
        notificationManager.notify(0, notification);
    }
    	
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onStart(Intent intent, int startId) {
	    handleCommand(intent);
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		handleCommand(intent);
		return START_STICKY;
	}	
}

@@ -529,19 +529,27 @@
 xt, 0, n
-ull
+ew Intent()
 , 0);%0A  
@@ -839,16 +839,77 @@
 LT_ALL;%0A
+        notification.flags %7C= Notification.FLAG_AUTO_CANCEL;%0A
         
@@ -1395,16 +1395,41 @@
 ation);%0A
+        this.stopSelf();%0A
     %7D%0A  
@@ -1701,16 +1701,16 @@
 ntent);%0A
-
 %09%09return
@@ -1716,16 +1716,20 @@
 n START_
+NOT_
 STICKY;%0A

Fix exception by null intent