平时积累(二)

1. 获取屏幕上正在显示的Activity:

 

    (1)ActivityManager mActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

 

    (2)ComponentName mComponentName = mActivityManager.getRunningTasks(1).get(0).topActivity;

 

2. 判断Activity是否在系统中存在:

 

    Intent intent = new Intent();

 

    intent.setClassName("包名", "类名");

 

    if(intent.resolveActivity(getPackageManager()) == null) {

 

    }

 

3. 获取StatusBar高度:

 

    Rect mDisplayFrame = new Rect();

 

    getWindow().getDecorView().getWindowVisibleDisplayFrame(mDisplayFrame);

 

    int statusBarHeight = mDisplayFrame.top;

 

4. 获取TitleBar高度:

 

    int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();

 

    int titleBarHeight = contentTop - StatusBar高度;

 

5. 获取应用程序主Activity:

 

    Intent intent = new Intent(Intent.ACTION_MAIN);

 

    intent.addCategory(Intent.CATEGORY_LAUNCHER);

 

    getPackageManager().queryIntentActivities(intent, 0);

 

6. PendingIntent:PendingIntent是一个Intent描述(包括Intent和Intent的接收器),我们将这个描述递交给其它应用程序,

 

    其它应用程序会在特定时间或特定条件下执行此描述所指定的任务。

 

7. 获取应用程序版本:

 

    应用程序版本号的是放在AndroidManifest.xml文件中的:

 

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

                     package="com.focus.fishme"

                     android:versionCode="2"

                     android:versionName="2.0"

                     />

 

    getPackageManager().getPackageInfo("com.focus.fishme", 0).versionCode;

 

8. 程序安装APK包:

 

    Uri packageUri = Uri.fromFile(new File(APK路径));

 

    PackageInstallObserver observer = new PackageInstallObserver();

 

    getPackageManager().installPackage(packageUri, observer, 1);

 

9. 程序打开浏览器浏览网站:

 

    Uri uri = Uri.parse("http://www.google.com.hk");

 

    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

 

    startActivity(intent);

 

10. 设置全屏的两种方法:

 

     (1)代码实现:

 

             requestWindowFeature(Window.FEATURE_NO_TITLE);

 

             getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,

 

                                             WindowManager.LayoutParams. FLAG_FULLSCREEN);

 

     (2)配置文件:

 

             android:theme = "@android:style/Theme.NoTitleBar.Fullscreen"

你可能感兴趣的:(android,浏览器,service,File,null,任务)