android UI install APK 与 监测 ACTION_PACKAGE_ADDED 事件

public class World extends Activity {


 private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();


@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       registerIntentReceivers() ;

     }


/**
     * Start to install APK file
     * @param file
     */
    private void openFile(File file) {
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(Intent.ACTION_VIEW);
 
        intent.setDataAndType(Uri.fromFile(file), APK_MIME_TYPE);
        startActivity(intent);

    }

private void registerIntentReceivers() {
        IntentFilter filter;
     
        filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addDataScheme("package");
        registerReceiver(mApplicationsReceiver, filter);
    }

    /**
     * Receives notifications when applications are added/removed.
     */
    private class ApplicationsIntentReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
             {   
                Log.i(TAG,"============================RETURN VALUE ");      
                         if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){   
                             Uri uri = null;
                             uri = intent.getData();
                             Log.i(TAG,"+++++++++++++++++++++++RETURN VALUE "+uri);    
                         }   
                          else  if(Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())){   
                                 Uri uri = null;
                                  uri = intent.getData();
                                  Log.i(TAG,"----------------------------RETURN VALUE "+uri);      
                         }   
             }
    }

}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭