一个例子
xml:
代码
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<receiver android:name=".OlympicsReceiver" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
java:
代码
public class OlympicsReceiver extends IntentReceiver
{
/*要接收的intent源*/
static final String ACTION = "android.intent.action.BOOT_COMPLETED";

public void onReceiveIntent(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
context.startService(new Intent(context,
OlympicsService.class), null);//启动倒计时服务
Toast.makeText(context, "OlympicsReminder service has started!", Toast.LENGTH_LONG).show();
}
}
}

注意:现在的IntentReceiver已经变为BroadcastReceiver,OnReceiveIntent为onReceive。所以java这边的代码为:
(也可以实现应用程序开机自动启动)
Code
public class OlympicsReceiver extends BroadcastReceiver
{
/*要接收的intent源*/
static final String ACTION = "android.intent.action.BOOT_COMPLETED";

public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
context.startService(new Intent(context,
OlympicsService.class), null);//启动倒计时服务
Toast.makeText(context, "OlympicsReminder service has started!", Toast.LENGTH_LONG).show();
//这边可以添加开机自动启动的应用程序代码
}
}
}

更多相关文章

  1. android 设置透明效果
  2. android基础知识15:获得android系统信息03—PackageManager
  3. Android知识体系结构概览
  4. Android应用程序框架
  5. ANDROID的MANIFEST.XML文件字段解析
  6. Android知识体系结构概览
  7. Android(安卓)待机时间
  8. 编译osg for android
  9. Android(安卓)Handler机制10之Native的实现

随机推荐

  1. java.lang.ClassCastException: android.
  2. android(2.0以后版本) 中读取联系人和通
  3. android Monkeyrunner:Python语法知识学
  4. Android(安卓)近百个项目的源代码,覆盖And
  5. 为android-support-v4.jar打包源码
  6. TextView添加Onclick点击无效没反应解决
  7. Delphi XE5 android 黑屏的临时解决办法
  8. Android(安卓)Intent 常见用法总结
  9. android中自定义Theme以及TitleBar
  10. Android中pm命令用法详解