Android 让一个Service开机自动启动
2010-09-15 00:06:00 来源:WEB开发网核心提示:注意:现在的IntentReceiver已经变为BroadcastReceiver,OnReceiveIntent为onReceive,Android 让一个Service开机自动启动(2),所以java这边的代码为:(也可以实现应用程序开机自动启动)Codepublic class OlympicsReceiver
注意:现在的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();
//这边可以添加开机自动启动的应用程序代码
}
}
}
更多精彩
赞助商链接