如何以编程方式显示“清除默认设置"? [英] How to show 'Clear Defaults' programmatically?

查看:91
本文介绍了如何以编程方式显示“清除默认设置"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用Home Launcher应用程序.我想清除默认的Home Launcher(例如Samsung Home)的默认设置.即,我想以编程方式显示Settings-> Applications->Manage Application->Samsung Home->clear defaults.

如何通过代码显示?

预先感谢

解决方案

注意: 由于此问题仅限于访问管理应用程序设置"选项,因此我的回答仅涉及这一点.您将必须找出一种获取实际软件包名称的方法.

此外,如果您的想法是还要通过代码自动清除默认值,那么就我所知,这是无法做到的.如果我在这方面做错了,有人可以纠正我.

话虽如此,这段代码将从您的应用程序打开特定应用程序的管理应用程序" 屏幕(必须提供程序包名称).

Intent showSettings = new Intent();
showSettings.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uriAppSettings = Uri.fromParts("package", "THE_APP_PACKAGE_NAME", null);
showSettings.setData(uriAppSettings);
startActivity(showSettings);

例如,如果Google Maps应用程序的软件包名称为com.google.android.apps.maps,则用它替换THE_APP_PACKAGE_NAME,代码将打开Goog​​le Maps应用程序的 Manage Application 屏幕./p>

更新:

PackageManager具有方法 clearPackagePreferredActivities 用于通过代码清除默认值.但是,无效似乎在较新的Android版本中有效: https://stackoverflow.com/a/10246711/450534

其他值得一读的帖子:

  1. https://stackoverflow.com/a/7750187/450534
  2. https://groups.google. com/forum/?fromgroups =#!topic/android-developers/Rzv8VU-EUAw

Now i am working on a Home Launcher application.I want to clear defaults of default home launcher(eg: Samsung Home). ie.I want to show Settings-> Applications->Manage Application->Samsung Home->clear defaults programmatically.

How to show this through code?

Thanks in Advance

解决方案

NOTE: Since this question is limited to accessing the Manage Application Settings options, my answer covers just that. You will have to figure out a way of getting the actual Package Name.

Also, if the idea is to also Clear the Defaults automatically via code, then that, to the best of my knowledge, cannot be done. Someone can correct me if I am wrong on this.

That being said, this piece of code will open the specific application's Manage Application screen from your app (the package name must be supplied).

Intent showSettings = new Intent();
showSettings.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uriAppSettings = Uri.fromParts("package", "THE_APP_PACKAGE_NAME", null);
showSettings.setData(uriAppSettings);
startActivity(showSettings);

For example, if the package name of the Google Maps application is com.google.android.apps.maps, the replace THE_APP_PACKAGE_NAME with it and the code will open the Manage Application screen for the Google Maps application.

UPDATE:

The PackageManager has a method, clearPackagePreferredActivities used to clear the default via code. However, that doesn't seem to work in newer Android versions: https://stackoverflow.com/a/10246711/450534

Other posts worth reading:

  1. https://stackoverflow.com/a/7750187/450534
  2. https://groups.google.com/forum/?fromgroups=#!topic/android-developers/Rzv8VU-EUAw

这篇关于如何以编程方式显示“清除默认设置"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆