ACTION_MY_PACKAGE_REPLACED not received

后端 未结 9 690
长发绾君心
长发绾君心 2020-12-08 00:59

I am using ACTION_MY_PACKAGE_REPLACED to receive when my app is updated or resinstalled. My problem is that the event is never triggered (I tried Eclipse and real device). T

9条回答
  •  伪装坚强ぢ
    2020-12-08 01:14

    Getting information from all the users I could solve my situation this way. All of them were right, with little points to notice:

    In manifest:

        
            
                
                
                
            
        
    

    And code:

    public class MyEventReceiver extends BroadcastReceiver
    {     
        @Override public void onReceive(Context context, Intent intent)
        {  
           if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) 
           {   if(intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
               {  //Restart services.
               }
           }
        }      
    }
    

    In my Android release (2.3 Gingerbread) I was not able to use MY_PACKAGE_REPLACED but we solved using PACKAGE_REPLACED (will advise of any app been replaced) but asking if it is ours with:

     if(intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
     {
     }
    

    Thanks to all

提交回复
热议问题