正常时插入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
471
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>
|