- 應用安裝後未運行
- 應用被手動(設置-應用-強制停止)或者其他應用強制停止了
- 你好,我寫了一個只有receiver和service的app,安裝後是無法接受系統廣播的,後來用了一個自定義的廣播啓動它過一次後,纔開始接受系統廣播了
- 我認爲你的那個app安裝之後不是處於停止狀態(關於驗證,你可以查看系統設置中的應用程序,那裏面能準確的看出是否爲停止狀態),另外我感覺你應該確認一下系統廣告是否發出,因爲你後面的說,自定義的廣告可以接收即表明這個程序處於非停止狀態。希望可以確認一下哈。
[代碼]xml代碼:
1
2
3
4
5
6
|
< receiver
android:name = "com.roger.BroadcastTest.Receiver"
android:enabled = "true"
android:exported = "true" > < intent-filter > < action
android:name = "android.intent.action.BOOT_COMPLETED" > < action
android:name = "com.roger.broadcast.test" > </ action ></ action ></ intent-filter > </ receiver > |
[代碼]java代碼:
1
2
3
4
5
6
7
8
|
public
class
Receiver extends
BroadcastReceiver { @Override public
void
onReceive(Context arg0, Intent arg1) { //
TODO Auto-generated method stub Log.i( "Tag" ,
"receive:"
+ arg1.getAction()); } } |
- framework中廣播分發者如何區分廣播接收器是否處於停止狀態
- framework中如何將應用從停止狀態切換到非停止狀態
[代碼]java代碼:
1
2
3
4
5
|
/**
@hide */ public
boolean
isExcludingStopped() { return
(mFlags&(FLAG_EXCLUDE_STOPPED_PACKAGES|FLAG_INCLUDE_STOPPED_PACKAGES)) ==
FLAG_EXCLUDE_STOPPED_PACKAGES; } |
[代碼]java代碼:
1
|
final
boolean
excludingStopped = intent.isExcludingStopped(); |
[代碼]java代碼:
1
2
3
4
5
6
|
if
(excludingStopped && isFilterStopped(filter, userId)) { if
(debug) { Slog.v(TAG,
"
Filter's target is stopped; skipping" ); } continue ; } |
[代碼]java代碼:
1
2
3
4
5
6
7
8
|
/** *
Returns whether the object associated with the given filter is *
"stopped," that is whether it should not be included in the result *
if the intent requests to excluded stopped objects. */ protected
boolean
isFilterStopped(F filter, int
userId) { return
false ; } |
[代碼]java代碼:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
|
@Override protected
boolean
isFilterStopped(PackageParser.ActivityIntentInfo filter, int
userId) { if
(!sUserManager.exists(userId)) return
true ; PackageParser.Package
p = filter.activity.owner; if
(p != null )
{ PackageSetting
ps = (PackageSetting)p.mExtras; if
(ps != null )
{ //
System apps are never considered stopped for purposes of //
filtering, because there may be no way for the user to //
actually re-launch them. return
(ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 &&
ps.getStopped(userId); } } return
false ; } |
[代碼]java代碼:
01
02
03
04
05
06
07
08
09
10
11
12
13
|
//
All available activities, for your resolving pleasure. final
ActivityIntentResolver mActivities = new
ActivityIntentResolver(); //
All available receivers, for your resolving pleasure. final
ActivityIntentResolver mReceivers = new
ActivityIntentResolver(); //
All available services, for your resolving pleasure. final
ServiceIntentResolver mServices = new
ServiceIntentResolver(); //
All available providers, for your resolving pleasure. final
ProviderIntentResolver mProviders = new
ProviderIntentResolver(); |
[代碼]java代碼:
1
2
3
|
void
setStopped( boolean
stop, int
userId) { modifyUserState(userId).stopped
= stop; } |
[代碼]java代碼:
1
2
3
4
5
6
|
//
Launching this app's activity, make sure the app is no longer //
considered stopped. try
{ AppGlobals.getPackageManager().setPackageStoppedState( next.packageName,
false ,
next.userId); /*
TODO: Verify if correct userid */ } |
[代碼]java代碼:
01
02
03
04
05
06
07
08
09
10
11
|
//
Service is now being launched, its package can't be stopped. try
{ AppGlobals.getPackageManager().setPackageStoppedState( r.packageName,
false ,
r.userId); } ActivityManagerService中 //
Content provider is now in use, its package can't be stopped. try
{ AppGlobals.getPackageManager().setPackageStoppedState( cpr.appInfo.packageName,
false ,
userId); } |
[代碼]java代碼:
1
2
3
4
5
|
//
Broadcast is being executed, its package can't be stopped. try
{ AppGlobals.getPackageManager().setPackageStoppedState( r.curComponent.getPackageName(),
false ,
UserHandle.getUserId(r.callingUid)); } |
[代碼]java代碼:
1
2
3
4
5
6
|
private
void
killProcesses() { ActivityManager
am = (ActivityManager)getActivity().getSystemService( Context.ACTIVITY_SERVICE); am.forceStopPackage(mEntry.mUiPackage); checkForceStop(); } |