我有一个来自 adb 的 logcat 文件。该文件如下所示,
09-03 17:12:04.562 479 957 I ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 1230
09-03 17:12:04.687 479 1030 I ActivityManager: Start proc com.amazon.mShop.android for activity com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity: pid=19164 uid=10158 gids={1006, 3003}
09-03 17:12:05.593 479 912 I ActivityManager: Starting: Intent { dat=?paramSuggestionText=cell%20phone flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 17:12:05.796 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +186ms (total +1s119ms)
09-03 17:12:08.601 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity: +3s925ms
09-03 17:12:08.601 479 620 I ActivityManager: Resumed Activity: com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity totalTime: 4037 ms
09-03 17:13:35.742 479 957 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity } from pid 19164
09-03 17:13:36.007 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity: +222ms
09-03 17:13:53.328 479 957 I ActivityManager: Starting: Intent { dat=?¶mSuggestionFilters=s%3An%3A%2C%3A4991425011%0As%3An%3A%2C%3A4991426011%0As%3An%3A%2C%3A5088769011%0As%3An%3A%2C%3A5263615011¶mDepartmentName=Programs flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 17:13:53.484 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +145ms
09-03 17:14:54.585 479 484 I ActivityManager: Starting: Intent { cmp=com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity } from pid 19164
09-03 17:14:54.718 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity: +102ms
09-03 17:15:30.210 479 957 I ActivityManager: Starting: Intent { flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:03:02.140 479 967 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x4000000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 19164
09-03 18:03:08.054 479 1005 I ActivityManager: Starting: Intent { dat= flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:03:08.171 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +105ms
09-03 18:04:24.937 479 967 I ActivityManager: Starting: Intent { cmp=com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity } from pid 19164
09-03 18:04:25.046 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity: +92ms
09-03 18:05:00.554 479 5949 I ActivityManager: Starting: Intent { flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:06:43.781 479 1019 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x4000000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 19164
09-03 18:07:12.984 479 1001 I ActivityManager: Starting: Intent { dat= flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:07:13.140 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +135ms
09-03 18:08:29.890 479 5949 I ActivityManager: Starting: Intent { cmp=com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity } from pid 19164
09-03 18:08:29.976 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity: +81ms
09-03 18:09:05.515 479 961 I ActivityManager: Starting: Intent { flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:18:42.132 479 1039 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity } from pid 19164
09-03 18:18:42.359 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.categoryBrowse.CategoryBrowseActivity: +144ms
09-03 18:19:09.890 479 1030 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x4000000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 19164
09-03 18:19:17.406 479 485 I ActivityManager: Starting: Intent { dat= flg=0x20000 cmp=com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity (has extras) } from pid 19164
09-03 18:19:17.515 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity: +97ms
09-03 18:20:58.500 479 5949 I ActivityManager: Starting: Intent { flg=0x20000 cmp=com.amazon.mShop.android/.search.image.SnapItActivity } from pid 19164
09-03 18:20:58.546 479 967 I ActivityManager: Starting: Intent { cmp=com.amazon.mShop.android/.search.image.SnapItPhotoCaptureActivity } from pid 19164
09-03 18:20:58.898 479 620 I ActivityManager: Displayed com.amazon.mShop.android/.search.image.SnapItPhotoCaptureActivity: +340ms (total +387ms)
09-03 18:21:26.156 479 1039 I ActivityManager: Starting: Intent { cmp=com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity } from pid 19164
09-03 18:21:26.359 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity: +185ms
09-03 18:21:42.750 479 957 W ActivityManager: Duplicate finish request for HistoryRecord{408f9da0 com.amazon.mShop.android/com.amazon.mShop.barcodeSearch.BarcodeFirstTryTipActivity}
09-03 18:26:05.968 479 963 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x4000000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 19164
09-03 18:27:53.515 479 957 I ActivityManager: Starting: Intent { flg=0x10000000 cmp=com.amazon.mShop.android/com.amazon.mobileads.mraid.MraidBrowser (has extras) } from pid 19164
09-03 18:27:54.750 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mobileads.mraid.MraidBrowser: +1s218ms
09-03 18:29:12.726 479 484 I ActivityManager: Starting: Intent { act=intentActionStartActivity flg=0x4000000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity (has extras) } from pid 19164
09-03 18:29:15.609 479 1039 I ActivityManager: Starting: Intent { flg=0x10000000 cmp=com.amazon.mShop.android/com.amazon.mobileads.mraid.MraidBrowser (has extras) } from pid 19164
09-03 18:29:16.882 479 620 I ActivityManager: Displayed com.amazon.mShop.android/com.amazon.mobileads.mraid.MraidBrowser: +1s261ms
09-03 18:32:41.750 479 967 I ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.amazon.mShop.android/com.amazon.mShop.home.HomeActivity } from pid 1230
现在我想从文件中提取活动名称。它要从与此类似的每一行中提取,
09-03 18:29:15.609 479 1039 I ActivityManager: Starting: Intent { flg=0x10000000 cmp=com.amazon.mShop.android/com.amazon.mobileads.mraid.MraidBrowser (has extras) } from pid 19164
或者
09-03 17:12:08.601 479 620 I ActivityManager: Resumed Activity: com.amazon.mShop.android/com.amazon.mShop.search.SearchActivity totalTime: 4037 ms
从这一行我只需要字符串com.amazon.mobileads.mraid.MraidBrowser 需要删除该行的其他部分。不包含Starting:Intent或ActivityManager: Resumed Activity:的行应该被删除。
最后我会有一个字符串序列,比如,
com.amazon.mobileads.mraid.MraidBrowser
com.amazon.mShop.search.SearchActivity
依此类推,具体取决于他们的行号。
我怎样才能做到这一点?我可以使用字符串标记器,但这是一个乏味且效率低下的过程,我认为正则表达式匹配或类似的东西会更好。