安卓系统浏览器开发

预置某个浏览器为系统默认的浏览器

描述:

当系统存在多个浏览器时,如何预置某个浏览器为系统默认的浏览器?

方法:

1.在PackageManagerService.java中的构造函数结尾添加:setDefaultBrowser();

2.setDefaultBrowser()的具体实现:

private final void setDefaultBrowser(){

                   Log.d("debug_default","setDefaultBrowser is called.");

                   if(!isFirstBoot()) {

                            Log.d("debug_default","not first boot, return");

                            return;

                            }

                  

                   String str1 = "android.intent.category.DEFAULT";

                   String str2 = "android.intent.category.BROWSABLE";

                   String str3 = "android.intent.action.VIEW";

                   //intent filter

                   IntentFilter filter = new IntentFilter(str3);

                   filter.addCategory(str1);

                   filter.addCategory(str2);

                   filter.addDataScheme("http");

        

                   //intent

                   Intent intent = new Intent(str3);

                   intent.addCategory(str2);

                   intent.addCategory(str1);

                   Uri uri = Uri.parse("http://");

                   intent.setDataAndType(uri, null);

                  

                   //set UC,if your want set other browser as default, modify below code, add package name and activiy name

                  ComponentName component = new ComponentName("packageName ","activityName");

                  

                   //find all browsers

                   List resolveInfoList = queryIntentActivities(intent,intent.getType(),PackageManager.GET_INTENT_FILTERS, 0);

                   int size = resolveInfoList.size();

                   ComponentName[] arrayOfComponentName = new ComponentName[size];

                   //make sure the default browser in phone

                   boolean no_UC = true;

                   for (int i = 0; i < size; i++)

                   {

                            ActivityInfo activityInfo = resolveInfoList.get(i).activityInfo;

                            String packageName = activityInfo.packageName;

                            String className = activityInfo.name;

                           if (packageName.equals("packageName")) no_UC = false;

                           

                            ComponentName componentName = new ComponentName(packageName, className);

                            arrayOfComponentName[i] = componentName;

                   }

                   if (no_UC){

                            return;

                            }

                   //set default

                   addPreferredActivity2(filter,IntentFilter.MATCH_CATEGORY_SCHEME, arrayOfComponentName,component);

                   }

3.增加addPreferredActivity2接口(还是在PackageManagerService.java中):

public void addPreferredActivity2(IntentFilter filter, int match,

            ComponentName[] set, ComponentName activity) {

        // writer

        synchronized (mPackages) {           

            Slog.i(TAG, "Adding preferred activity " + activity + ":");

            filter.dump(new LogPrinter(Log.INFO, TAG), "  ");

          

mSettings.editPreferredActivitiesLPw(0).addFilter(

                    new PreferredActivity(filter, match, set, activity));

            mSettings.writePackageRestrictionsLPr(0);

        }

    }

修改网页默认字体大小

安卓系统浏览器开发_第1张图片

用HTMLViewer浏览html页面,点击页面中的邮箱地址,打开邮箱应用 

安卓系统浏览器开发_第2张图片

 

你可能感兴趣的:(android,java,servlet)