public:it:android

这是本文档旧的修订版!


Android

  • /data/data/为 app 包路径
  • /data/app/ 下为用户安装的 app
  • /system/app/ 下为系统原装 app
  • FIXME
  • 在android设备设置界面上修改网络后,信息会保存在 /data/data/com.android.providers.settings/databases/settings.db
  • uboot logo; kernel logo; initlogo.rle; bootanimation.zip
  • 可通过屏蔽 init.rc 里相应的服务 bootlogoupdater bootanim 来屏蔽; 或设置属性
  • 一屏logo:logo.bin, 使用 mtk 线刷 flash_tool 刷入
  • 二屏为执行/system/bin/boot_logo_updater; 图片位置存疑: 可能在 /dev/logo ? 或者就是与动画同一处 /system/media/bootanimation.zip
  • 三屏为 andorid 通用的动画阶段

动画阶段

  1. 开机动画程序 bootanimation
    • 代码位置: frameworks/base/cmds/bootanimation/BootAnimation.cpp
    • 调用位置: 在init.rc中调用 bootanimation (/system/bin/bootanimation)
  1. bootanimation 加载文件流程
    • 判断是否存在“/data/local/bootanimation.zip”或“/system/media/bootanimation.zip”,
    • 若存在的话,则显示bootanimation.zip中的动画;
    • 若不存在的话,则显示系统默认的 Android 闪动画面. (/system/framework/framework-res.apk)
  1. bootanimation.zip 制作: 制作
    • 解压后一般包含文件 desc.txt 与文件夹 part0, part1;
    • part0, part1 里包含动画帧图片, png 格式, 按名称排列顺序;
    • 压缩格式是zip,压缩方式必须选择为“存储”;
    • desc.txt 格式:
      320 480 10
      #宽  高  每秒帧数
      p 1 0 part0
      # 播放次数1 间隔0 指定文件夹part0
      p 0 0 part1
      # 无限播放  间隔0 指定文件夹part1

备忘

  • Android Debug Bridge ←-大部分命令行需求都可以从这个官方文档中获得,包括文件拷贝、应用管理、包管理、网络转发、截屏录屏及其它。
  • 装完驱动,打开USB调试, 连接电脑后, 就可以用 adb 工具来连接内置shell
    adb shell 
    shell@***:/ $
    # 如果已 root , 则可以直接 su 获取 root 身份:
    su 
    root@***:/ $
  • 拷贝文件: adb pull <remote> <local> , adb push <local> <remote>
  • 获取系统版本:getprop ro.build.version.release
  • 获取系统api版本:getprop ro.build.version.sdk
  • 获取cpu信息:cat /proc/cpuinfo
  • 获取网络IP配置:netcfg
  • 获取网络信息: netstat
  • 获取开机时间: cat /proc/stat | grep btime, 为 unixtime格式, 或者 cat /proc/uptime, 第一个时间为开机至今运行秒数
  • 应用入口, 在AndroidManifest.xml中的 相应 Activity 下添加以下:
    <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 

    即表示该 Activity 为应用启动时加载的入口 Activity

  • Context 运行环境上下文, 为 Activity 的父类之一, 本 Activity 的 Context 可直接用 this; 整应用的 context 用 getApplicationContext(), 前者生命期与该 Activity 同, 后者生命期随整个应用.
  • 启动另一个 Activity
    Intent intent =new Intent(CurrentActivity.this,OtherActivity.class);
    startActivity(intent); // 启动 OtherActivity
    //finish(); // 结束 CurrentActivity

    通讯用 Bundle

  • 系统通知 Notification
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Intent;
    public class MainActivity extends AppActivity {
    ......
        private void mynotify() {
            NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
     
            Intent intent = new Intent(MainActivity.this,MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity .this,0,intent,0);
     
            Notification notification = new Notification.Builder(getApplicationContext())
                    .setContentTitle("标题")
                    .setAutoCancel(true) // 点击即消失
                    .setContentText("内容")
                    .setSmallIcon(R.mipmap.c_launcher)
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setContentIntent(pendingIntent)
                    .setWhen(System.currentTimeMillis())
                    .build();
     
            manager.notify(1, notification);// 第一个参数为预定的 id , 应用可用此 id 删除通知.
        }
    }

    注意, 此处的PendingIntent.getActivity(MainActivity .this,0,intent,0); 第四个 flag 参数, 可能可以解决 PendingIntent 已经存在时的 putExtra 数据未更新问题.

  • 延迟执行
    import android.os.Handler;
    ...
        private final Handler mDelayHandler = new Handler();
        private final Runnable mDelayRunnable = new Runnable() {
            @Override
            public void run() {
                mynotify();// or whatever you what to do.
            }
        };
        private void delayed(int delayMillis) {
            mDelayHandler.removeCallbacks(mDelayRunnable);// 清理上次
            mDelayHandler.postDelayed(mDelayRunnable, delayMillis);
        }
    ...
     
  • 异步任务 短时间异步任务可用 android.os.AsyncTask(限定在UI线程里使用); 长时间异步任务使用 java.util.concurrent 提供的 Executor,ThreadPoolExecutorFutureTask;
  • android.webkit.WebView 不响应 on click , 不过可以响应 on long click. 或者直接重写 onTouchEvent 来模拟 click;
  • android.webkit.WebView 加载的网页点击链接时会默认弹出浏览器加载,可以直接设置 WebViewClient 来在本WebView 打开:
    mywebview.setWebViewClient(new WebViewClient());
  • Android Emulator 模拟器默认上不了网, 基本原因是 DNS 设置不对, 可以采取以下步骤来设置:
    1. 开启模拟器运行;
    2. 打开windows命令行, 在 sdk 下载目录下找到 adb.exe 所在目录,进入目录, 命令行运行
      >cd c:\andorid\sdk\platform-tools
      >adb shell
      # 顺利进入会出现类似以下的提示符
      root#generic_86:/ #
       
    3. 继续输入 getprop, 可以看到 DNS 被默认设置为了 10.0.2.3
      getprop
      #结果显示:
      ...
      [net.dns1]: [10.0.2.3]
      ...
      ...
    4. 修改设置为你的 DNS, 大功告成
      setprop net.dns1 192.168.0.1
  • Android Studio 出现 “Gradle sync failed: Unable to start the daemon process.” 错误, 并带有java奔溃提示. 猜测可能原因是java虚拟机内存分配不够, 解决办法:
    • 办法一: 以管理员身份运行 Android Studio;
    • 办法二: 修改项目gradle.properties文件,添加下面一行代码:
      org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m
  • Gradle 的代理设置,如果是 socks5 代理, 得在项目 gradle.properties 添加如下设置
    org.gradle.jvmargs=-DsocksProxyHost=<your-socks5-ip> -DsocksProxyPort=<your-socks5-port>
  • cocos2d-x 在安卓上使用的是 android.opengl.GLSurfaceView 来渲染. SurfaceView 独立于窗口绘制表面,即拥有单独的重绘机制,与父窗口脱离。
  • public/it/android.1643349375.txt.gz
  • 最后更改: 2022/01/28 13:56
  • oakfire