谁能帮我弄到原图,求大佬的坐姿表情包原图

16092人阅读
android 应用(4)
&android4.2系统中是在frameworks/base/services/java/com/android/server/am/ActivityManagerService.java的finishBooting()方法中发送开机广播。
final void finishBooting() {
IntentFilter pkgFilter = new IntentFilter();
pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
pkgFilter.addDataScheme(&package&);
mContext.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
if (pkgs != null) {
for (String pkg : pkgs) {
synchronized (ActivityManagerService.this) {
if (forceStopPackageLocked(pkg, -1, false, false, false, false, 0)) {
setResultCode(Activity.RESULT_OK);
}, pkgFilter);
synchronized (this) {
// Ensure that any processes we had put on hold are now started
final int NP = mProcessesOnHold.size();
if (NP & 0) {
ArrayList&ProcessRecord& procs =
new ArrayList&ProcessRecord&(mProcessesOnHold);
for (int ip=0; ip&NP; ip++) {
if (DEBUG_PROCESSES) Slog.v(TAG, &Starting process on hold: &
+ procs.get(ip));
startProcessLocked(procs.get(ip), &on-hold&, null);
if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
// Start looking for apps that are abusing wake locks.
Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
// Tell anyone interested that we are done booting!
SystemProperties.set(&sys.boot_completed&, &1&);
SystemProperties.set(&dev.bootcomplete&, &1&);
for (int i=0; i&mStartedUsers.size(); i++) {
UserStartedState uss = mStartedUsers.valueAt(i);
if (uss.mState == UserStartedState.STATE_BOOTING) {
uss.mState = UserStartedState.STATE_RUNNING;
final int userId = mStartedUsers.keyAt(i);
Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
broadcastIntentLocked(null, null, intent,
null, null, 0, null, null,
android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
false, false, MY_PID, Process.SYSTEM_UID, userId);
最后是通过broadcastIntentLocked()方法发送,broadcastIntentLocked()方法中会为将要发送的intent设置一个flag:
// By default broadcasts do not go to stopped apps.
intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
android官方文档中对此flag描述如下:
public static final int FLAG_EXCLUDE_STOPPED_PACKAGES
Added in API level 12
If set, this intent will not match any components in packages that are currently stopped. If this is not set, then the default behavior is to include such applications in the result.
Constant Value: 16 (0x)
意思是当前处于停止状态的包中的组件无法收到设置了这个flag的Intent。
&android3.1的更新文档中有对停止状态进行说明():
Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).
&当应用第一次被按照但是没有被启动,或者应用在应用管理中被手动停止时,应用处于停止状态。
&由上面的分析可知,Android4.2中应用接收开机广播(android.intent.action.BOOT_COMPLETED)失败的原因就在于安装应用后没有先启动。应用需要在安装后启动一次,才能正常接收开机广播。经过验证发现,系统级别的应用,即使不启动,也可以正常接收开机广播。这里的系统级别是指放在/system/app/目录下的应用。
&验证过程如下:
1.Eclipse中新建一个ReceiverTest工程,包名为com.example.receivertest。
2.在包com.example.receivertest中新建一个MyReceiver类,继承BroadcastReceiver类。文件内容:
package com.example.
import android.content.BroadcastR
import android.content.C
import android.content.I
import android.media.AudioM
import android.util.L
public class MyReceiver extends BroadcastReceiver {
private static final String TAG = &ReceiverTest&;
public void onReceive(Context ctx, Intent arg1) {
// TODO Auto-generated method stub
Log.d(TAG,&Volume Test receive Boot_completed!&);
final Context context =
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
Log.d(TAG,&Thread start!&);
AudioManager mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
while(true){
max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_SYSTEM );
current = mAudioManager.getStreamVolume( AudioManager.STREAM_SYSTEM );
Log.d(TAG, &@@@@@@@@@@@@@@maxVolume : & + max + &, currentVolume : & + current);
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}).start();
3.&在AndroidManifest.xml中注册MyReceiver,并设置其Intent filter,同时注释掉Eclipse自动生成的Activity。内容如下:
&?xml version=&1.0& encoding=&utf-8&?&
&manifest xmlns:android=&/apk/res/android&
package=&com.example.receivertest&
android:versionCode=&1&
android:versionName=&1.0& &
android:minSdkVersion=&8&
android:targetSdkVersion=&17& /&
&uses-permission android:name=&android.permission.RECEIVE_BOOT_COMPLETED& /&
&application
android:allowBackup=&true&
android:icon=&@drawable/ic_launcher&
android:label=&@string/app_name&
android:theme=&@style/AppTheme& &
android:name=&com.example.receivertest.MainActivity&
android:label=&@string/app_name& &
&intent-filter&
&action android:name=&android.intent.action.MAIN& /&
&category android:name=&android.intent.category.LAUNCHER& /&
&/intent-filter&
&/activity&
&receiver android:name=&com.example.receivertest.MyReceiver& &
&intent-filter&
&action android:name=&android.intent.action.BOOT_COMPLETED& /&
&/intent-filter&
&/receiver&
&/application&
&/manifest&
adb连接上android设备,在Eclipse中Run as Android Application运行此应用。重启android设备,从开机log看应用中的MyReceiver并没有接收到开机广播。卸载应用,通过adb 把工程bin目录中APK push到android设备的/system/app/目录并重启后,开机log上显示MyReceiver成功接收到开机广播。
3.卸载应用,取消AndroidManifest.xml中的注释,重新编译运行应用。Android设备上显示默认的helloworld后重启设备,log显示MyReceiver成功接收到开机广播。
&所以对于android3.1以后得系统版本,如果要应用接收开机广播有两种方法:
1.将应用push到/system/app/目录。
2.安装应用后先启动一次,适用于有Activity的应用。
参考文章:;&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:31827次
排名:千里之外
(1)(1)(1)(1)(2)(1)关于BOOT_COMPLETED广播-自启动 - 简书
关于BOOT_COMPLETED广播-自启动
文章摘要:1、BOOT_COMPLETED在ActivityManagerService中由系统发送。2、应用可以监听该广播,成为自启动权限,但是这样会有很多缺点,最大的缺点就是拖慢开机进度,影响用户体验。3、开机状态会sys.boot_completed,可以通过该属性状态得到开机状态。
一、BOOT_COMPLETED广播是什么?1、BOOT_COMPLETED是系统在开机加载完毕后发送的。如下:
* Broadcast Action: This is broadcast once, after the system has finished
* booting.
It can be used to perform application-specific initialization,
* such as installing alarms.
You must hold the
* {@link android.Manifest.permission#RECEIVE_BOOT_COMPLETED} permission
* in order to receive this broadcast.
* &p class="note"&This is a protected intent that can only be sent
* by the system.
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
从注释可以看出,该广播需要权限才能接收,并且只有系统有权限发送它。2、接收BOOT_COMPLETED广播,需要权限,该权限:android.Manifest.permission#RECEIVE_BOOT_COMPLETED。如下是系统对该权限的介绍:
&!-- Allows an application to receive the
{@link android.content.Intent#ACTION_BOOT_COMPLETED} that is
broadcast after the system finishes booting.
If you don't
request this permission, you will not receive the broadcast at
that time.
Though holding this permission does not have any
security implications, it can have a negative impact on the
user experience by increasing the amount of time it takes the
system to start and allowing applications to have themselves
running without the user being aware of them.
As such, you must
explicitly declare your use of this facility to make that visible
to the user. --&
&permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"
android:permissionGroup="android.permission-group.APP_INFO"
android:protectionLevel="normal"
android:label="@string/permlab_receiveBootCompleted"
android:description="@string/permdesc_receiveBootCompleted" /&
a、从ProtectionLevel来看,应用可以申请该权限。android:protectionLevel="normal"
b、如文中所述,申请该权限,有许多缺点。
I、增加系统启动的时间。因为系统启动过程中,广播接收方会收到广播,并可以启动自身或者加载某些资源。
II、自启动,不经用户确认。应用都说在用户的点击或者请求发起下启动的,自启动可以绕过用户,自我自动。
III、不要想着自己的小行为用户觉察不到,系统会将自启动的应用程序形成一份列表名单,show给用户,并交由用户管理。
二、如何接收该广播。1、前面提到了,接收BOOT_COMPLETED广播,需要权限,该权限:android.Manifest.permission#RECEIVE_BOOT_COMPLETED。在AndroidManifest.xml中增加权限信息:
&uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&
2、增加广播注册。在AndrodManifest.xml中,增加广播注册信息:
&receiver android:name="com.example.androidtest.BootCompleteReceiver"&
&intent-filter&
&action android:name="android.intent.action.BOOT_COMPLETED"/&
&/intent-filter&
&/receiver&
三、BOOT_COMPLETED系统如何发送的。1、在系统启动的过程中,ActivityManagerServie发送的该广播。frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java#finishBooting
if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
// Start looking for apps that are abusing wake locks.
Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
// Tell anyone interested that we are done booting!
SystemProperties.set("sys.boot_completed", "1");
// And trigger dev.bootcomplete if we are not showing encryption progress
if (!"trigger_restart_min_framework".equals(SystemProperties.get("vold.decrypt"))
|| "".equals(SystemProperties.get("vold.encrypt_progress"))) {
SystemProperties.set("dev.bootcomplete", "1");
for (int i=0; i&mStartedUsers.size(); i++) {
UserStartedState uss = mStartedUsers.valueAt(i);
if (uss.mState == UserStartedState.STATE_BOOTING) {
uss.mState = UserStartedState.STATE_RUNNING;
final int userId = mStartedUsers.keyAt(i);
Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
broadcastIntentLocked(null, null, intent, null,
new IIntentReceiver.Stub() {
public void performReceive(Intent intent, int resultCode,
String data, Bundle extras, boolean ordered,
boolean sticky, int sendingUser) {
synchronized (ActivityManagerService.this) {
requestPssAllProcsLocked(SystemClock.uptimeMillis(),
true, false);
0, null, null,
android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
AppOpsManager.OP_NONE, true, false, MY_PID, Process.SYSTEM_UID,
scheduleStartProfilesLocked();
2、从上面粘贴的代码中,我们可以得出如下结论。
a、开机启动广播,是区分多用户的。
b、在开机广播发送的流程中,会向系统写入sys.boot_completed,我们依据它可以得出当前系统是否已开机加载结束,这对一些系统服务或者app判断应用状态很有效。SystemProperties.set("sys.boot_completed", "1");
老夫聊发安卓狂,左代码、右文章。心得见解,汇总即篇章。为报倾情随大牛,提见解、纳短长。后使用快捷导航没有帐号?
查看: 217|回复: 2
三方apk接收不到开机广播
[DESCRIPTION]
自启动失败/接收不到BOOT_COMPLETED广播可能的原因:
[SOLUTION]
(1)、BOOT_COMPLETED对应的action和uses-permission没有一起添加
需要三方应用在Manifest.xml中写入:
&action android:name=&android.intent.action.BOOT_COMPLETED& &
&uses-permission android:name=&android.permission.RECEIVE_BOOT_COMPLETED&
(2)、应用安装到了sd卡内,安装在sd卡内的应用是收不到BOOT_COMPLETED广播的.
(概率出现 )
(3)、对于android3.1以后版本,如果要应用接收开机广播有两种方法:
a).将应用预置到/system/app/目录。
b).安装应用后先启动一次,适用于有Activity的应用。
1、BOOT_COMPLETED这个广播比较特殊,预置到system/app下面的apk才会通过
android.intent.action.BOOT_COMPLETED来开机自启动。而预置到
data/app,vendor/app下面的三方apk,若安装从来没有启动过和被用户手动强制停止
,它就是处于“stopped state”(此应用的信息保存在
/data/system/users/0/package-restrictions.xml中),它的接收器将会无法接收任
何广播,无法开机之后自动启动。但是安装这个应用之后只要是有手动去点击下这个
apk,下次开机就肯定是会自动启动起来的,也是接收这个BOOT_COMPLETED广播。
2、与此同时系统增加了2个Flag:FLAG_INCLUDE_STOPPED_PACKAGES和
FLAG_EXCLUDE_STOPPED_PACKAGES ,来标识一个intent是否激活处于“stopped
state”的应用。
3、Google允许应用和后台服务通过给广播intent设置
FLAG_INCLUDE_STOPPED_PACKAGES来唤醒处于“stopped state”的程序,也就是用户
自己写的广播intent可以控制这个机制,但是系统自带的广播intent默认都是
FLAG_EXCLUDE_STOPPED_PACKAGES,由于不能修改,所以就没法通过系统广播自启动了。
nice nice nice
论坛资料为网友自由上传,与本论坛无关。
Powered by
关注一牛微信
获取手机验证码2014年1月 移动开发大版内专家分月排行榜第二
2014年1月 移动开发大版内专家分月排行榜第二
2014年1月 移动开发大版内专家分月排行榜第二
2014年1月 移动开发大版内专家分月排行榜第二
2014年1月 移动开发大版内专家分月排行榜第二
本帖子已过去太久远了,不再提供回复功能。}

我要回帖

更多关于 向大佬低头 原图 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信