Android background music service

Do it without service https://web.archive.org/web/20181116173307/http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion If you are so serious about doing it with services using mediaplayer Intent svc=new Intent(this, BackgroundSoundService.class); startService(svc); public class BackgroundSoundService extends Service { private static final String TAG = null; MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.idil); … Read more

Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

I got solution. For pre-8.0 devices, you have to just use startService(), but for post-7.0 devices, you have to use startForgroundService(). Here is sample for code to start service. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(new Intent(context, ServedService.class)); } else { context.startService(new Intent(context, ServedService.class)); } And in service class, please add the code below for notification: … Read more

getApplication() vs. getApplicationContext()

Very interesting question. I think it’s mainly a semantic meaning, and may also be due to historical reasons. Although in current Android Activity and Service implementations, getApplication() and getApplicationContext() return the same object, there is no guarantee that this will always be the case (for example, in a specific vendor implementation). So if you want … Read more

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

First, get your tombstone stack trace, it will be printed every time your app crashes. Something like this: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Build fingerprint: ‘XXXXXXXXX’ pid: 1658, tid: 13086 >>> system_server <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 64696f7e r0 00000000 … Read more

Android – Listen For Incoming SMS Messages

public class SmsListener extends BroadcastReceiver{ private SharedPreferences preferences; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if(intent.getAction().equals(“android.provider.Telephony.SMS_RECEIVED”)){ Bundle bundle = intent.getExtras(); //—get the SMS message passed in— SmsMessage[] msgs = null; String msg_from; if (bundle != null){ //—retrieve the SMS message received— try{ Object[] pdus = (Object[]) bundle.get(“pdus”); msgs = … Read more

Determining the current foreground application from a background task or service

With regards to “2. How my background application can know what the application currently running in the foreground is.” Do NOT use the getRunningAppProcesses() method as this returns all sorts of system rubbish from my experience and you’ll get multiple results which have RunningAppProcessInfo.IMPORTANCE_FOREGROUND. Use getRunningTasks() instead This is the code I use in my … Read more