Create Notification with BroadcastReceiver

前端 未结 3 1382
小鲜肉
小鲜肉 2021-01-17 09:08

I tried to create a Notification with this Code:

private void setNotificationAlarm(Context context) 
{
    Intent intent = new Intent(getApplicationContext()         


        
3条回答
  •  执笔经年
    2021-01-17 09:37

    you can use

    Intent switchIntent = new Intent(BROADCAST_ACTION);

    instead of using

    Intent intent = new Intent(getApplicationContext() , MyNotification.class);

    in here BROADCAST_ACTION is action that you are defining in manifest

    
        
            
        
    
    

    you can catch it by using that action name

    public class MyNotification extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String act = "your package.ANY_NAME";
            if(intent.getAction().equals(act)){
    
                //your code here
            }
    }}
    

提交回复
热议问题