| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.IntentFilter; |
| | | import android.content.pm.ServiceInfo; |
| | | import android.graphics.BitmapFactory; |
| | | import android.graphics.Color; |
| | | import android.os.Build; |
| | |
| | | */ |
| | | public class ForeService extends Service { |
| | | |
| | | final String TAG=ForeService.class.getName(); |
| | | final String TAG = ForeService.class.getName(); |
| | | |
| | | @Override |
| | | public IBinder onBind(Intent intent) { |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @SuppressLint("ForegroundServiceType") |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | Log.d(TAG, "ForeService onCreate() 进程Id:"+android.os.Process.myPid() ); |
| | | startForeground(1, getNotification(getString(R.string.app_name), "Running")); |
| | | // Log.d(TAG, "ForeService onCreate() 进程Id:" + android.os.Process.myPid()); |
| | | // try { |
| | | // // Kotlin 示例 |
| | | // if (Build.VERSION.SDK_INT >= 34) { |
| | | // startForeground(1, getNotification(getString(R.string.app_name), "Running"), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); |
| | | // } else { |
| | | // startForeground(1, getNotification(getString(R.string.app_name), "Running")); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // } |
| | | } |
| | | |
| | | @Override |