change PREFERRED_APPLICATIONS in Android
2011-05-04 16:29
267 查看
"Result set changed" means that the set of packages matching that intent has changed from the set you specified when you created the default - - so the default is no longer valid. Your list of components (which you are currently setting to null) needs to contain all homescreen apps present on device, not just yours.
Here's example code that I have tested (using adb shell am start http://www.google.co.uk/ ) and used to set the default browser. XXX represents a customer name that I had to black out.
Note that in order to call addPreferredActivity you must have compiled against a minimum-sdk version of 8 (2.2) and you must have specified the SET_PREFERRED_APPLICATIONS permission. That permission is protection level 2, so you need to be signed with the same certificate as PackageManager.
ETA - if you marked this response down, could you let me know why. The code I posted above is tested and working...
http://stackoverflow.com/questions/3836215/android-change-default-home-application
Here's example code that I have tested (using adb shell am start http://www.google.co.uk/ ) and used to set the default browser. XXX represents a customer name that I had to black out.
Note that in order to call addPreferredActivity you must have compiled against a minimum-sdk version of 8 (2.2) and you must have specified the SET_PREFERRED_APPLICATIONS permission. That permission is protection level 2, so you need to be signed with the same certificate as PackageManager.
IntentFilter filter = new IntentFilter(); filter.addAction("android.intent.action.VIEW"); filter.addCategory("android.intent.category.DEFAULT"); filter.addDataScheme("http"); Context context = getApplicationContext(); ComponentName component = new ComponentName("com.opera.mini.XXX", "com.opera.mini.XXX.CustomerBrowser"); ComponentName[] components = new ComponentName[] {new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"), component}; pm.addPreferredActivity(filter, IntentFilter.MATCH_CATEGORY_SCHEME, components, component);[/code]
ETA - if you marked this response down, could you let me know why. The code I posted above is tested and working...
http://stackoverflow.com/questions/3836215/android-change-default-home-application
相关文章推荐
- Wakelocks: Detect No-Sleep Issues in Android* Applications(转载)
- Using your own SQLite database in Android applications
- Using your own SQLite database in Android applications
- Using MQTT in Android mobile applications
- ANR in Android Applications
- JavaScript in Android Applications
- Using MultipartEntity in Android applications
- How to use AlertDialog.Builder in Android applications
- Preserving User Preferences in Android Applications
- 解决Android Studio 或eclipse运行时出现Duplicate files copied in APK main/AndroidManifest.xml
- Android Studio安装后'tools.jar' seems to be not in Android Studio classpath.的问题
- light black color code in android
- Android naming standard in res
- Application Installation Failed in Android Studio
- Install Android, Cordova, and Ionic Framework in U
- 解决‘tools.jar’ seems to be not in android studio classpath 问题
- com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
- com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
- android 的injustdecodebounds