当前位置: 代码迷 >> Android >> 求Android
  详细解决方案

求Android

热度:36   发布时间:2016-05-01 21:47:34.0
求Android 高手指点
我想写一段代码,让它在安装本软件的时候就启动,并一直监视数据库的数据。

在网上搜的代码如下:在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!

跪求高手帮忙啊 !!


或者给一个可以跑的例子啊!!!!摆脱了

------解决方案--------------------
小弟觉得 怎么也要运行一次本程序吧
------解决方案--------------------
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已经说的很清楚了,新安装的程序是接收不到这个广播的。反而是别的程序可以收到你安装程序的广播,你的方法不可行。

------解决方案--------------------
嗯,应该需要运行一次程序呢。可能也有解决方案。目前大多数第一次运行的时候跑一次。
------解决方案--------------------
楼主我不是说了你的那个方案不行吗。请换方案。
------解决方案--------------------
代码没错,你思维错了,请看API
------解决方案--------------------
哦。这个方案明显不行,API已经说了啊。你要么就是运行一次程序的时候执行你的代码模块。我刚才百度了一下,好像只能这样了。怎么得也要跑一次程序的。。
------解决方案--------------------
XML code
<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>
------解决方案--------------------
Note that the newly installed package does not receive this broadcast.
如果不行真的没办法了
------解决方案--------------------
至少也要执行一下吧,安装后又不会自动运行。写个服务在后台监控就行了
------解决方案--------------------
这个至少得运行一次后,才能做到。
其实你这个想法就不是很正确啊,程序都没运行过,监听它的数据库没任何意义啊。
------解决方案--------------------
探讨

引用:
这个至少得运行一次后,才能做到。
其实你这个想法就不是很正确啊,程序都没运行过,监听它的数据库没任何意义啊。


就是运行了我的小游戏啊!!!!

就算是运行了也不能启动这段代码啊
  相关解决方案