How to change the default Android browser's homepage within an app?

后端 未结 6 1108
刺人心
刺人心 2020-12-11 10:07

Within my app, is it possible to programatically change the Android browser\'s homepage url? If so, how can I accomplish this?

For example, if you run this popular

6条回答
  •  温柔的废话
    2020-12-11 10:18

    I did not try this myself, but BrowserSettings has a public interface setHomePage:

    public void setHomePage(Context context, String url) {
        Editor ed = PreferenceManager.
                getDefaultSharedPreferences(context).edit();
        ed.putString(PREF_HOMEPAGE, url);
        ed.commit();
        homeUrl = url;
    }
    

    It is used in BrowserBookmarksPage like this:

    BrowserSettings.getInstance().setHomePage(this, [URL]);
    

    But that BrowserSettings class is only accessible from that package. So maybe accessing the shared preferences is easier... ?

    MORE...

    Not really here to be giving a lesson. It may be possible to do, maybe with some native code accessing the XML file with the preferences for the Browser or other ways like this, but...

    • No matter what you do, this would be going "around" the security in place. Your app should not be able to change the homepage of the Browser (or it would be in the documentation)
    • Even if it is possible to find a way to do it (through NDK or finding undocumented interfaces), it would most likely stop working at some point with some new release of Android, which is probably not what you would want.
    • I understand some app already do it, and IMHO, that's bad. Does not mean that your app should be doing the same and frustrate more potential users.

提交回复
热议问题