Posts

Showing posts with the label Android Service

Add My App To AutoStart Apps List In Android Programmatically

Answer : Some of the applications such as Whatsapp and Facebook might have been whiltlisted thats why they have automatic Autostart option enabled. But i have tried the following code for Xiaomi Devices hope this might help!! String manufacturer = "xiaomi"; if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) { //this will open auto start screen where user can enable permission for your app Intent intent = new Intent(); intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); startActivity(intent); } This screen/behaviour is not native to Android, meaning the screen you show comes from a custom rom, probably from a particular manufacturer. Like you said the answers in the other question do not work but they are the only native way to start an application on boot/start. Check if the app/custom rom has an API (a particul...

Android - Implementing StartForeground For A Service?

Answer : I'd start by completely filling in the Notification . Here is a sample project demonstrating the use of startForeground() . From your main activity, start the service with the following code: Intent i = new Intent(context, MyService.class); context.startService(i); Then in your service for onCreate() you would build your notification and set it as foreground like so: Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.app_icon) .setContentTitle("My Awesome App") .setContentText("Doing some work...") .setContentIntent(pendingIntent).build(); startForeground(1337, notification); Solution for Oreo 8.1 I've encountered some problems such as RemoteServiceException becau...