Today urgent follow up a Baidu video app can not adjust the problem of Baidu Bar app, of course, this is only found in 4.x Android system, in the 2.x version, all normal, (in fact, is 3.1 and above the version of the problem) specific scenarios for:
1, paste the app installed successfully but did not start, trying to from the video app via Sendbroadcast mode: failed
2, bar app process by the user forced to kill, trying to from the video app through the Sendbroadcast way: Failed
3, paste the app is in the start state, trying to sendbroadcast from the video app by the way: success
Look at the video to tune up the code logic, is this:
| 12345 |
Intent intent = newIntent("com.baidu.tieba.action.INVOKE");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("type", "frs");intent.putExtra("fname", "李毅");activity.sendBroadcast(intent); |
So direct location problem: Must be a high version of the Android system, in the broadcast of the appropriate, unable to adjust the start (in the stopped state) of the app, open the official document checked: Http://developer.android.com/about/versions /android-3.1.html#launchcontrols writes very clearly, probably means:
Starting with Android 3.1, two new flags were defined for intent, flag_include_stopped_packages and Flag_exclude_stopped_packages, respectively. Used to control whether the intent is working for apps that are in a stopped state, as the name implies:
Flag_include_stopped_packages: Indicates an app that contains a non-starter
Flag_exclude_stopped_packages: Does not include apps that are not started
It is worth noting that Android 3.1 started with the system adding the FLAG_EXCLUDE_STOPPED_PACKAGES flag to all intent broadcasts. This is done to prevent broadcasts from inadvertently or unnecessarily opening a background service that does not start the app. If you want to force an app that doesn't start, the background service or application can wake up by adding the Flag_include_stopped_packages flag to the broadcast intent, sample code:
| 123456 |
< Code class= "Java plain" >intent Intent = new intent ( "Com.baidu.tieba.action.INVOKE" intent.addflags (intent.flag_activity_new_task); intent.addflags (intent. Flag_include_stopped_packages); intent.putextra ( "FRS" intent.putextra ( "Liyi" activity.sendbroadcast (intent); |
If your project relies on an Android SDK that is under 3.1, then writing directly like this will be problematic, and you will find that intent.flag_include_stopped_packages cannot be correctly identified, so a relatively safe approach is Write the value directly in:
| 123456789 |
Intent intent = new Intent("com.baidu.tieba.action.INVOKE"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 3.1以后的版本直接设置Intent.FLAG_INCLUDE_STOPPED_PACKAGES的value:32if (android.os.Build.VERSION.SDK_INT >= 12) { intent.setFlags(32);}intent.putExtra("type", "frs");intent.putExtra("fname", "李毅");activity.sendBroadcast(intent); |
Above, Mark!
Turn the third-party app by broadcasting on Android