我想写一段代码,让它在安装本软件的时候就启动,并一直监视数据库的数据。在网上搜的代码如下:在androidManifext.xml中代码:
<receiver android:name=".BootReceiver" >
  <intent-filter>  <!-- 系统启动完成后会调用 -->  <action android:name="android.intent.action.ACTION_PACKAGE_ADDED" >
  </action>
  </intent-filter>
  </receiver>在java代码中:
public class BootReceiver extends BroadcastReceiver {     @Override    public void onReceive(Context context, Intent intent) {     //这里写你需要的代码!   
  }   }  可是我做完这个之后发现它并没有执行(我是做了一个每1分钟的监控输出)。若果把以上代码单独写出来就会是报错:[2012-03-20 11:50:50 - Android-04] No Launcher activity found!
[2012-03-20 11:50:50 - Android-04] The launch will only sync the application package on the device!跪求高手帮忙啊 !!
或者给一个可以跑的例子啊!!!!摆脱了

解决方案 »

  1.   

    Broadcast Action: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.
    API已经说的很清楚了,新安装的程序是接收不到这个广播的。反而是别的程序可以收到你安装程序的广播,你的方法不可行。
      

  2.   

    代码没错,你思维错了,请看API
      

  3.   


    我是刚从javaEE 转做android   什么都不懂 上面的方案也不是我想出来的。网上抄的,而且网上搜到的都和这个大差不差。我要是自己能想方案就好了。
      

  4.   

    哦。这个方案明显不行,API已经说了啊。你要么就是运行一次程序的时候执行你的代码模块。我刚才百度了一下,好像只能这样了。怎么得也要跑一次程序的。。
      

  5.   

    <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.intent.action.PACKAGE_ADDED"  />
                <action android:name="android.intent.action.PACKAGE_INSTALL" />
                <data android:scheme="package" />
    </intent-filter>
      

  6.   

    Note that the newly installed package does not receive this broadcast.
    如果不行真的没办法了 
      

  7.   


    楼主,我不是解释过了吗。不是你这么写你的思路有问题怎么执行这个代码,你那个广播根本就不能监听到自己的程序,api不是说的很清楚了吗。Note that the newly installed package does not receive this broadcast.
    你在activity的oncreate方法里面写一个函数就是了。设置一个判断这个函数只执行一次神马的随便你了。