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

后端 未结 6 1115
刺人心
刺人心 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:17

    There is NO WAY to change the homepage url of the browser.

    com.android.browser opens/creates a preference with MODE_PRIVATE. So the files's attributes are became as -rw-rw---- And also browser app's menifest has no sharedUserId attribute.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.browser">
    

    The app doesn't provide the chance to share app's preference file.

    0 讨论(0)
  • 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.
    0 讨论(0)
  • 2020-12-11 10:20

    This cannot be accomplished programmatically from within your app.

    Edit: I downloaded the application you provided, and it does appear to accomplish what you're looking for. How exactly it was done, I have no clue. I can't find anything online on how to do this. I'm interested to see if anyone has any ideas on how they accomplished this.

    0 讨论(0)
  • 2020-12-11 10:22

    I authored the app called My Home Page (https://play.google.com/store/apps/details?id=com.aac.myhomepage) where I needed to accomplish this exact task. I looked everywhere possible and couldn't find a method of doing this so I ended up using two workarounds which really aren't great options in my opinion.

    1) I offer a root option for those who have rooted devices where I simply access the SharedPreferences XML file of the browser and, using regular expressions, swap out the value of the home page with the one needed.

    2) Copy the URL to the clipboard and tell the user how to accomplish changing the default home page.

    Note that I did not use root access without the user's permission nor did I change the home page without the user's permission. This is the purpose of the app and the home page isn't changed without the user explicitly doing so.

    I recently noticed that the ad SDKs were doing this but something tells me that they aren't doing it in a proper manner and I don't have any interest i

    0 讨论(0)
  • 2020-12-11 10:31

    I hava a opinion: Maybe you can read the source code of Browser and find the code like this:

    SharedPreferences prefs = mContext.getSharedPreferences(RECOVERY_PREFERENCES, Context.MODE_PRIVATE);
    

    and get the SharedPreferences of Browser,then find the place to set homepage, change it. Is that possible?

    0 讨论(0)
  • 2020-12-11 10:39

    Im guessing the app developer didnt write it in his code to do that. I think one of the 11 ad sdks he has in his app is causing it.

    He has

    adserver.adview
    adwhirl
    amobee.onlinehapi
    apperhand
    google
    inmobi.androidsdk
    jumptap.adtag
    mdotm.android.ads
    millenialmedia.android
    mobclix.android.sdk
    zestadz.android
    

    as a side note this is ridiculous.

    0 讨论(0)
提交回复
热议问题