android programmatically update apk and see the result of the installation

前端 未结 3 2008
耶瑟儿~
耶瑟儿~ 2020-12-13 20:23

I\'m writing an app updater for my app. After I make sure I have my apk on the device, this is what I do from within the app I\'m trying to update:

Intent pr         


        
3条回答
  •  醉话见心
    2020-12-13 21:19

    All you can do is register a receiver with the intent filters like android.intent.action.PACKAGE_INSTALL or android.intent.action.PACKAGE_REPLACED from which you can restart your application back again.

    
            
                
                
            
             
                
                
            
            
                
                
            
             
                
                
            
             
                
                
            
        
    
    

    And

    public class BootService extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
    
        if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
            Intent serviceIntent = new Intent();
            serviceIntent.setClass(context,Controller.class);
            serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(serviceIntent);
        } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
            Intent serviceIntent = new Intent();
            serviceIntent.setClass(context, Controller.class);
            serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(serviceIntent);
        }
      }
    }
    

提交回复
热议问题