Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Gemons4Ever · Jun 27, 2020 at 10:33 AM · androidpluginnative pluginservicenotifications

How to create android notification to keep foreground service alive?

Hi community,

I have been trying to implement a foreground service for android using native code. I have no issue with creating the service itself, but I need to create a notification to inform the user, otherwise the system kills the service after 5 seconds.

I tried this code to create the notification:

 NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
         .setSmallIcon(R.drawable.notification_icon)
         .setContentTitle(textTitle)
         .setContentText(textContent)
         .setPriority(NotificationCompat.PRIORITY_DEFAULT);

But it causes the following error. Apparently Unity cannot find the NotificationCompat class.

 06-27 11:30:59.643  9748  9777 E Unity   : AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationCompat$Builder;
 06-27 11:30:59.643  9748  9777 E Unity   : java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationCompat$Builder;

Does anybody know an example of how to start a foreground service in android from unity? Or a recent example of how to implement notifications? Most examples on the internet are too old and don't work for android version of API 26 (Oreo) or above.

Regards, David

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gemons4Ever · Jun 27, 2020 at 11:02 AM 0
Share

$$anonymous$$aybe the problem is that I use an androidx library in Android Studio and NotificationCompat is androidx.core.app.NotificationCompat. I found that some people are having problems combining androidx libraries and unity. Still I don't know how to solve the issue.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Gemons4Ever · Apr 08, 2021 at 04:25 PM

Hi,

yes. Actually I hired a freelancer on fiverr to do it for me. The Plugin he made didn't work properly but it helped me to spot the errors I made. It was worth the money afer I spent more than a week without any luck.

Mostly these were errors in the gradle files and unity setup.

Here the link to the fiverr page of that guy: https://www.fiverr.com/koradiyaabhay/develop-android-native-plugin-for-unity?source=order_page_summary_gig_link_title&funnel=9ea84578-4cc3-4263-96fe-fc8e23bc7f8e

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by marcosocram · Apr 08, 2021 at 03:00 AM

Did you have any luck creating a Foreground Service plugin?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rendering Android native view with OpenGL 0 Answers

Unity 2019.3.5f1 Android Build (IL2CPP) crash Log 0 Answers

android time cheat plugin problem with broadcastreceiver 1 Answer

Why the Unity3D only can load 32-bit native plugin(.so) on android platform? 1 Answer

Cannot get value from sensor as Android background service 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges