zoukankan      html  css  js  c++  java
  • 获取浏览器的homepage

    主要知识点:
    跨进程访问数据

    首先修改浏览器源码:
    BrowserSettings.java

    private static String getSDMCDefaultSharedPreferencesName(Context context) {
            return context.getPackageName() + "_preferences";
        }
        
        private BrowserSettings(Context context) {
            mContext = context.getApplicationContext();
    
    /*sky modify just for test*/ //mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); //因为这个默认的mode是MODE_PRIVATE mPrefs = mContext.getSharedPreferences(getSDMCDefaultSharedPreferencesName(mContext), Context.MODE_WORLD_READABLE);//修改为可读 /*sky modify over*/ mAutofillHandler = new AutofillHandler(mContext); mManagedSettings = new LinkedList<WeakReference<WebSettings>>(); mCustomUserAgents = new WeakHashMap<WebSettings, String>(); mAutofillHandler.asyncLoadFromDb(); BackgroundHandler.execute(mSetup); }

    然后就是跨APK访问数据了:

            Context otherAppsContext = null;
            
            try{
                otherAppsContext = context.createPackageContext("com.android.browser",0);
            }catch (Exception e){
                Log.i("BootReceiver-BootBrowser", "NameNotFoundException");
            }
            
            try{
                //com.android.browser_preferences.xml
                SharedPreferences mPrefs = otherAppsContext.getSharedPreferences("com.android.browser_preferences",Context.MODE_PRIVATE);
                String homepage = mPrefs.getString("homepage","hahahaha");
                
                Log.i("BootReceiver-BootBrowser","homepage="+homepage);
            }catch(Exception e){
                Log.i("BootReceiver-BootBrowser", "Exception#####");
            }
            
            //隐式访问浏览器APK
            Intent intent = new Intent();        
            intent.setAction("android.intent.action.VIEW");    
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //Uri content_url = Uri.parse("http://www.baidu.com");   
            Uri content_url = Uri.parse(homepage);  
            intent.setData(content_url);  
            context.startActivity(intent);        
            
            //显式访问浏览器APK
            Intent intent = new Intent();  
            //intent.addCategory(Intent.CATEGORY_LAUNCHER); 
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        
            ComponentName cn = new ComponentName("com.android.browser", "com.android.browser.BrowserActivity");             
            intent.setComponent(cn);  
            
            context.startActivity(intent); 

    参考:  
    跨apk访问SharedPreferences   
    http://www.cnblogs.com/leaven/archive/2012/07/28/2613291.html 

  • 相关阅读:
    Oracle 常用的十大 DDL 对象
    Oracle DML
    Oracle 的常用概念
    Spring 4 : 整合 SSH
    Spring3 (事务管理)
    Spring2
    Spring 学习笔记一
    Xpath helper下载
    爬取链家北京市二手房的单个房源页信息
    爬取链家北京市二手房的链家编号
  • 原文地址:https://www.cnblogs.com/lijunamneg/p/3312592.html
Copyright © 2011-2022 走看看