<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/android-start-auto-run-app-dev/</link>
<title><![CDATA[Android开机自动启动的应用开发 ]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Sat, 16 Oct 2010 01:47:03 +0000</pubDate> 
<guid>https://www.heckjj.com/android-start-auto-run-app-dev/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 微软雅黑;">目前有一个项目需要开发一个开机自启动的GTD应用程序来提醒用户的一些重要日程安排，对于这类应用，Android提供了一个BroadcastReceiver组件来对于应用程序的运行环境进行监听，并对于各种事件进行对应的处理。使用BroadcastReceiver十分简单，我们只需要在AndroidManifest.xml或者我们的代码中进行相应的注册（这也是Android开发的两种方式）。这样之后在广播事件到来时，我们就能通过重写BroadcastReceiver的onReceive()方法来执行相应的操作。<br/><br/>下面简单来演示如何开发开机自启动应用。<br/>1.建立一个名为Boot的Android应用。<br/>2.简单实现BootActivity的应用界面，在此实现了一个TextView的实例来开机后显示一句话内容。<br/>TextView textView=new TextView(this);<br/>textView.setText(&quot;这是一个开机自启动应用程序&quot;);<br/>setContentView(textView);<br/>3.创建一个BootBroadcastReveiver的类，实现了抽象类BroadcastReceiver。以下是整个代码。</span><textarea name="code" class="java" rows="15" cols="100">
package com.blessdyb.boot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootBroadcastReceiver extends BroadcastReceiver &#123;

&nbsp;&nbsp;&nbsp;&nbsp;@Override
&nbsp;&nbsp;&nbsp;&nbsp;public void onReceive(Context context, Intent intent) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intent bootActivityIntent=new Intent(context,BootActivity.class);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bootActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.startActivity(bootActivityIntent);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&#125;</textarea><span style="font-family: 微软雅黑;"><br/>4.在AndroidMenifest.xml中配置Receiver。我们在Android Menifest Application中进行配置。 <br/> <br/>其结果即为如下XML配置（application子目录）：</span><textarea name="code" class="xml" rows="15" cols="100">
&lt;receiver android:name=&quot;.BootBroadcastReceiver&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;intent-filter&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot;&gt;&lt;/action&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/intent-filter&gt;
&lt;/receiver&gt;</textarea><span style="font-family: 微软雅黑;"><br/>5.当然，我们需要对我们的应用进行权限许可，只有通过这种形式才能真正地让我们的应用程序实现开机自启动。我们需要在AndroidMenifext.xml中进行如下配置。<br/> <br/>配置完成后，会在XML文件中以如下形式显示（menifext子目录）<br/>&lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot;/ &gt;</span><br/>Tags - <a href="https://www.heckjj.com/tags/%25E7%25A7%25BB%25E5%258A%25A8%25E5%25BC%2580%25E5%258F%2591/" rel="tag">移动开发</a> , <a href="https://www.heckjj.com/tags/%25E6%2589%258B%25E6%259C%25BA%25E5%25BC%2580%25E5%258F%2591/" rel="tag">手机开发</a> , <a href="https://www.heckjj.com/tags/android/" rel="tag">android</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/android-start-auto-run-app-dev/#blogcomment</link>
<title><![CDATA[[评论] Android开机自动启动的应用开发 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/android-start-auto-run-app-dev/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>