IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 插入U 盘,默认弹出通知使用RkExplorer.apk打开 -> 正文阅读

[移动开发]插入U 盘,默认弹出通知使用RkExplorer.apk打开

正常时插入U 盘,默认弹出通知,点击通知会打开如下界面
ACTIVITY com.android.documentsui/.files.FilesActivity
由于File App com.android.documentsui已经被移除,需要更换为如下界面
/system/app/RkExplorer/RkExplorer.apk
com.android.rk/.RockExplorer

弹出的通知信息如下:
settings
SanDisk USB drive
For transferring photos and media

在源码中搜索“For transferring photos and media”,发现定义如下:
frameworks/base/core/res/res/values-en-rAU/strings.xml
“For transferring photos and media”

继续搜索ext_media_ready_notification_message,发现在是在StorageNotification.java中发送的这个通知。
/frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java

351      private Notification onVolumeMounted(VolumeInfo vol) {
379              final CharSequence text = mContext.getString(
380                      R.string.ext_media_ready_notification_message, disk.getDescription());
381  
382              final PendingIntent browseIntent = buildBrowsePendingIntent(vol);
383              final Notification.Builder builder = buildNotificationBuilder(vol, title, text)
384                      .addAction(new Action(R.drawable.ic_folder_24dp,
385                              mContext.getString(R.string.ext_media_browse_action),
386                              browseIntent))
387                      .addAction(new Action(R.drawable.ic_eject_24dp,
388                              mContext.getString(R.string.ext_media_unmount_action),
389                              buildUnmountPendingIntent(vol)))
390                      .setContentIntent(browseIntent)
391                      .setCategory(Notification.CATEGORY_SYSTEM);

如下,设置了一个隐式intent

642      private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) {
643          final StrictMode.VmPolicy oldPolicy = StrictMode.allowVmViolations();
644          try {
645              final Intent intent = vol.buildBrowseIntentForUser(vol.getMountUserId());
646  
647              final int requestKey = vol.getId().hashCode();
648              return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
649                      PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
650          } finally {
651              StrictMode.setVmPolicy(oldPolicy);
652          }
653      }
654  

frameworks/base/core/java/android/os/storage/VolumeInfo.java

454      public @Nullable Intent buildBrowseIntentForUser(int userId) {
455          final Uri uri;
456          if ((type == VolumeInfo.TYPE_PUBLIC || type == VolumeInfo.TYPE_STUB)
457                  && mountUserId == userId) {
458              uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, fsUuid);
459          } else if (type == VolumeInfo.TYPE_EMULATED && isPrimary()) {
460              uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY,
461                      DOCUMENT_ROOT_PRIMARY_EMULATED);
462          } else {
463              return null;
464          }
465  
466          final Intent intent = new Intent(Intent.ACTION_VIEW);
467          intent.addCategory(Intent.CATEGORY_DEFAULT);
468          intent.setDataAndType(uri, DocumentsContract.Root.MIME_TYPE_ITEM);
469  
470          // note that docsui treats this as *force* show advanced. So sending
471          // false permits advanced to be shown based on user preferences.
472          intent.putExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, isPrimary());
473          return intent;
474      }

frameworks/base/core/java/android/provider/DocumentsContract.java

668          public static final String MIME_TYPE_ITEM = "vnd.android.document/root";
669  

打开File app的Manifast.xml,可以发发现如下intentfilter

<activity
        android:name=".files.FilesActivity"
        android:documentLaunchMode="intoExisting"
        android:theme="@style/DocumentsTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.document/root" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.document/directory" />
        </intent-filter>
    </activity>    

所以需要在RkExplorer.apk中添加如下intent-filter即可

 <activity android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/app_name" android:launchMode="singleTop" android:name=".RockExplorer">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.document/root" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.document/directory" />
        </intent-filter>
    </activity>
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-03-30 18:36:39  更:2022-03-30 18:37:55 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年9日历 -2024/9/22 1:34:03-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码