Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2091246
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: LINUX

2009-04-08 09:46:38

  1. Define a class derived from class BroadcastReceiver;
  2. Register broadcast receiver;
    MyBroadcastReceiver myReceiver = new MyBroadcastReceiver();
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_INSTALL);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
    ...
    filter.addDataScheme("package"); //This line is very important. Otherwise,
    broadcast can't be received.

    registerReceiver(myReceiver, filter);

    Notes: The package name is Intent.mData. Intent.mData is not available in SDK 1.0, but it can be retrieved by calling Intent.getDataString();
  3. Uninstall package
    1. Uninstall application in code
      Uri uri = Uri.formParts("package", , null);
      Intent intent = new Intent(Intent.ACTION_DELETE, uri);
      context.startActivity(intent);
    2. Check if application is uninstalled successfully
      1. Uninstall succeeded
        - Define a broadcast receiver to monitor Intent.ACTION_PACKAGE_REMOVED
        - Register such broadcast receiver
      2. Uninstall failed/succeeded
        - Launch package uninstalled with:
        activity.startActivityForResult(intent, );

        - Get result
        protected void onActivityResult(int requestCode, int resultCode, Intent data)
        {
            if (requestCode == )  //resultCode always is 0, and the intent argument 'data' is always null
            {
               //call packagemanager.getPackageInfo, return null if package is uninstalled
            }
        }

        Note: This method is not invoked if the package is uninstalled successfully
    3. ...
  4. ...
阅读(2411) | 评论(0) | 转发(0) |
0

上一篇:[Android] Get IP Address

下一篇:Webkit Development

给主人留下些什么吧!~~