Giter Club home page Giter Club logo

my-notifications's Introduction

References:


This specific permission must be granted manually by the user in android Settings, after that your service will be executed as you bound the permission to your service in AndroidManifest.xml with this:

    <service android:name=".PcNotification"
    android:label="PCNotificationService"
    android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>

The problem is that most users won't know where to grant this permission (e.g inside android Settings), so you can open it for them with this:

    startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));

From the documentation on how we Inject dependencies into Android classes, we can learn the following:

Hilt can provide dependencies to other Android classes that have the @AndroidEntryPoint annotation.

Hilt currently supports the following Android classes:

Application (by using @HiltAndroidApp) ViewModel (by using @HiltViewModel) Activity Fragment View Service BroadcastReceiver

So when you subclass any of these Android classes, you don't ask Hilt to inject dependencies through the constructors. Instead, you annotate it with @AndroidEntryPoint, and ask Hilt to inject its dependencies by annotating the property with @Inject:

    @AndroidEntryPoint
    class ExampleActivity : AppCompatActivity() {
    
        @Inject
        lateinit var mAdapter: SomeAdapter 
        ...
    }

So, in your case you should inject MyRepository in MyActivity and MyService like this:

    @AndroidEntryPoint
    class MyService: Service() {
    
        @Inject
        lateinit var myRepository: MyRepository
        ...
    }
    
    @AndroidEntryPoint
    class MyActivity: AppCompatActivity(R.layout.my_layout) {
    
        @Inject
        lateinit var myRepository: MyRepository
        ...
    }

And remember:

Fields injected by Hilt cannot be private

That's it for Android classes that is supported by Hilt.

If you wonder what about classes not supported by Hilt (ex: ContentProvider)?! I recommend learning how from this tutorial @EntryPoint annotation on codelab (also don't forget to check the documentation for how to Inject dependencies in classes not supported by Hilt).


If you're working with Android 7.0+, WhatsApp uses MessageStyle Expanded Notifications. Here - https://developer.android.com/training/notify-user/expanded.html#message-style

To retrieve all 5 messages from a notification like

MyFriend (5 messages) testt

Do this:

    Bundle extras = mysbn.getNotification().extras;
    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)){
    Parcelable b[] = (Parcelable[]) extras.get(Notification.EXTRA_MESSAGES);
    
            if(b != null){
                content = "";
                for (Parcelable tmp : b){
    
                    Bundle msgBundle = (Bundle) tmp;
                    content = content + msgBundle.getString("text") + "\n";
    
                    /*Set<String> io = msgBundle.keySet(); // To get the keys available for this bundle*/
    
                }
            }
        }

my-notifications's People

Contributors

guilhermemagro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.