{"id":9199,"date":"2024-05-09T10:01:01","date_gmt":"2024-05-09T02:01:01","guid":{"rendered":""},"modified":"2024-05-09T10:01:01","modified_gmt":"2024-05-09T02:01:01","slug":"Android \u5982\u4f55\u5b8c\u6574\u7684\u83b7\u53d6\u5230\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868","status":"publish","type":"post","link":"https:\/\/mushiming.com\/9199.html","title":{"rendered":"Android \u5982\u4f55\u5b8c\u6574\u7684\u83b7\u53d6\u5230\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

    \u63a5\u5230\u4ea7\u54c1\u7ecf\u7406\u7684\u9884\u7814\u9700\u6c42\uff0c\u8bf4\u5e0c\u671b\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u3002\u8fd9\u4e2a\u95ee\u9898\u5e94\u8be5\u4e0d\u96be\uff0c\u53ea\u8981\u662f\u8981\u628a\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\u6574\u7406\u548c\u9a8c\u8bc1\u4e00\u4e0b\u3002<\/p>\n

    \u5bf9\u4e8e\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\uff0c\u6211\u4e2a\u4eba\u662f\u5f88\u719f\u6089\u7684\uff0c\u56e0\u4e3a\u6211\u7684\u534e\u4e3a\u624b\u673a\u4e0a\uff0c\u624b\u673a\u7ba1\u5bb6\u5929\u5929\u4f1a\u5728\u901a\u77e5\u680f\u5f39\u51fa\u201dxxx\u5e94\u7528\u5c1d\u8bd5\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u88ab\u7981\u6b62\u201d\u3002\u6240\u4ee5\uff0c\u5f88\u660e\u663e\uff0c\u8ddf\u6743\u9650\u662f\u6709\u5173\u7cfb\u7684\u3002\u4e8e\u662f\uff0c\u6211\u5c1d\u8bd5\u53bb\u67e5\u627e\u5230\u5e95\u662fmanifest\u6e05\u5355\u4e2d\u7684\u54ea\u4e00\u4e2ause-permission\u5f15\u8d77\u3002\u7ed3\u679c\uff0c\u627e\u4e86\u5f88\u4e45\uff0c\u7ffb\u4e86\u5f88\u4e45\uff0c\u5e76\u6ca1\u6709\u54ea\u4e2a\u6743\u9650\u5bf9\u5df2\u5b89\u88c5\u7684\u5e94\u7528\u5217\u8868\u8d1f\u8d23\u3002<\/p>\n

    \u4f46\u5947\u602a\u7684\u662f\uff0c\u6211\u7684\u624b\u673a\u4e0a\u51e0\u4e4e\u5168\u90e8\u7684\u8f6f\u4ef6\u90fd\u58f0\u660e\u4e86\u8fd9\u4e2a\u6743\u9650\u3002\u4e8e\u662f\uff0c\u5c1d\u8bd5\u53bb\u6c42\u52a9\u5176\u4ed6\u7ec4\u5458\uff0c\u54a8\u8be2\u4e86\u51e0\u4e2a\uff0c\u4e0d\u5c11\u4eba\u4e00\u8138\u61f5\u903c\u7684\u8868\u793a\u8fd9\u662f\u4e2a\u4ec0\u4e48\u73a9\u610f\u3002\u5728\u4ed6\u4eec\u7684\u624b\u673a\u4e0a\u538b\u6839\u5c31\u6ca1\u6709\u89c1\u8fc7\u8fd9\u4e2a\u4e1c\u897f\u3002<\/p>\n

    \u5728\u5199demo\u9a8c\u8bc1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53d1\u73b0\u975e\u5e38\u7b80\u5355\u7684\u4e00\u4e2ademo\uff0c\u5c45\u7136\u4e5f\u58f0\u660e\u4f7f\u7528\u4e86\u8be5\u6743\u9650\u3002 \u4e00\u5f00\u59cb\u6000\u7591\uff0c\u96be\u9053\u662f\u68c0\u6d4b\u5230\u4e86\u76f8\u5173\u4ee3\u7801\u81ea\u52a8\u7533\u8bf7\u4e86\u6743\u9650\uff1f\u53d1\u73b0\u5168\u90e8\u6ce8\u91ca\u540e\u8fd8\u662f\u4f1a\u58f0\u660e\u3002 \u540e\u6765\uff0c\u5c06\u6e05\u5355\u6587\u4ef6\u4e2d\u7684\u552f\u4e00\u7684\u8bbf\u95eeInternet\u6743\u9650\u53bb\u6389\uff0c\u8fd9\u6837\u624d\u6b63\u5e38\u3002<\/p>\n

    \u6240\u4ee5\uff0c\u5f97\u51fa\u4e86\u4e00\u4e2a\u7ed3\u8bba\u5c31\u662f\uff0c\u56fd\u5185\u90e8\u5206\u5382\u5546\u6bd4\u5982\u534e\u4e3a\u3001oppo,\u4ed6\u4eec\u5c06\u201d\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u201d\u7684\u6743\u9650\u66b4\u9732\u7ed9\u4e86\u7528\u6237\uff0c\u8ba9\u7528\u6237\u53ef\u4ee5\u81ea\u7531\u51b3\u5b9a\u5141\u8bb8\u6216\u8005\u7981\u6b62\u5e94\u7528\u8bbf\u95ee\u8be5\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u8fd9\u4e2a\u6743\u9650\u7c7b\u4f3c\u4e8e\u9644\u52a0\u7684\u9ed8\u8ba4\u6743\u9650\uff0c\u4e00\u65e6app\u58f0\u660e\u4e86\u4efb\u4f55\u6743\u9650\uff0c\u90a3\u4e48\u201d\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u201d\u7684\u6743\u9650\u4e5f\u4f1a\u88ab\u9644\u52a0\u8fdb\u6765\u3002\u4f46\u8fd9\u4e2a\u6743\u9650\u4e5f\u4e0d\u662f\u592a\u654f\u611f\uff0c\u6240\u4ee5\u5bf9\u4e8e\u7528\u6237\u662f\u65e0\u611f\u77e5\u7684\u3002\u8fd9\u91cc\u7684\u65e0\u611f\u77e5\u6307\u7684\u662f\u4e0d\u4f1a\u5728\u5e94\u7528\u4e2d\u53bb\u4e3b\u52a8\u8ba9\u6211\u4eec\u5f39\u7a97\u7533\u8bf7\u6743\u9650\uff0c\u624b\u673a\u7ba1\u5bb6\u5f39\u51fa\u7684\u901a\u77e5\u4e0d\u7b97\u3002<\/p>\n

\u597d\u5427\uff0c\u8bf4\u4e86\u8fd9\u4e48\u591a\uff0c\u770b\u4e00\u4e0b\u8fc7\u7a0b\u4e2d\u76843\u79cd\u65b9\u6848\u3002<\/p>\n

\u65b9\u68481<\/h2>\n
\n
private<\/span> void<\/span> getAppList<\/span>() {\n    PackageManager pm = getPackageManager();\n    \/\/ Return a List of all packages that are installed on the device.<\/span>\n    List<PackageInfo> packages = pm.getInstalledPackages(0<\/span>);\n    for<\/span> (PackageInfo packageInfo : packages) {\n        \/\/ \u5224\u65ad\u7cfb\u7edf\/\u975e\u7cfb\u7edf\u5e94\u7528<\/span>\n        if<\/span> ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0<\/span>) \/\/ \u975e\u7cfb\u7edf\u5e94\u7528<\/span>\n        {\n            System.out<\/span>.println(\"MainActivity.getAppList, packageInfo=\"<\/span> + packageInfo.packageName);\n        } else<\/span> {\n            \/\/ \u7cfb\u7edf\u5e94\u7528 <\/span>\n        }\n    }\n}<\/code><\/pre>\n

\u6b64\u65b9\u6cd5\u5728\u534e\u4e3a\u3001oppo\u624b\u673a\u4e0a\uff0c\u628a\u6743\u9650\u7981\u6b62\u540e\uff0c\u5c31\u4e0d\u80fd\u6b63\u786e\u83b7\u53d6\u5230\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u4e86\u3002<\/p>\n

\u65b9\u68482<\/h2>\n
\n

    \u8003\u8651\u5230\u65b9\u68481\u53d7\u6743\u9650\u7684\u5f71\u54cd\uff0c\u4e8e\u662f\u8003\u8651\u7528adb\u547d\u4ee4\u53bb\u83b7\u53d6\u5df2\u5b89\u88c5\u7684\u5e94\u7528\u5217\u8868\u3002<\/p>\n

\u547d\u4ee4:adb shell pm list package -3<\/p>\n

    \u4e0a\u9762\u7684\u547d\u4ee4\u53ef\u4ee5\u83b7\u53d6\u5230\u624b\u673a\u4e0a\u5df2\u5b89\u88c5\u7684\u7b2c3\u65b9\u5e94\u7528\u5217\u8868\uff0c\u53bb\u6389-3\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u83b7\u53d6\u5230\u5168\u90e8\u7684\u5e94\u7528\u5217\u8868\u3002\u672c\u6765\u5bf9\u8fd9\u4e2a\u65b9\u6848\u62b1\u633a\u5927\u7684\u671f\u671b\u7684\uff0c\u4f46\u662f\u6700\u7ec8\u53d1\u73b0\u5728oppo\u624b\u673a\u4e0a\uff0c\u5982\u679c\u7981\u6b62\u4e86\u83b7\u53d6\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u7684\u6743\u9650\uff0c\u90a3\u4e48\u7ed3\u679c\u5c31\u4f1a\u53d7\u5230\u5f71\u54cd\uff0c\u65e0\u5948\u53c8\u4e0d\u884c\u3002<\/p>\n

\u5c0f\u63d2\u66f2:\u5728\u4ee3\u7801\u8c03\u7528\u547d\u4ee4\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e2a\u5751,<\/p>\n

private<\/span> void<\/span> runCommand<\/span>() {\n    try<\/span> {\n        Process process = Runtime.getRuntime().exec(\"adb shell pm list package -3\"<\/span>);\n        BufferedReader bis = new<\/span> BufferedReader(new<\/span> InputStreamReader(process.getInputStream()));\n        String line = null<\/span>;\n        while<\/span> ((line = bis.readLine()) != null<\/span>) {\n            System.out<\/span>.println(\"MainActivity.runCommand, line=\"<\/span> + line);\n        }\n    } catch<\/span> (IOException e) {\n        System.out<\/span>.println(\"MainActivity.runCommand,e=\"<\/span> + e);\n    }\n}<\/code><\/pre>\n

    \u7528\u4ee3\u7801\u53bb\u6267\u884c\u4e86 adb shell pm list package -3\u7684\u547d\u4ee4\uff0c\u53d1\u73b0\u4e00\u76f4\u62a5IOException\uff0c\u6700\u7ec8\u8017\u8d39\u4e00\u5b9a\u7684\u65f6\u95f4\uff0c\u5b9a\u4f4d\u5230\u95ee\u9898\u3002\u6211\u4eec\u4f7f\u7528adb shell\u662f\u56e0\u4e3a\u624b\u673a\u8ddfpc\u8981\u8fde\u63a5\uff0c\u4f46\u662f\u5728\u624b\u673a\u4e0a\u8fd0\u884c\u65f6\uff0c\u5176\u5b9e\u4e0d\u7528\u52a0adb shell\uff0c\u76f4\u63a5\u6267\u884c\u201dpm list package -3\u201d\u5373\u53ef\u3002<\/p>\n

\u65b9\u68483<\/h2>\n
\n

    \u91c7\u7528getPackageManager().queryIntentActivities(intent,PackageManager.MATCH_ALL)\u53bb\u67e5\u8be2\u662f\u5426\u6709\u7b26\u5408\u6307\u5b9a\u610f\u56fe\u7684Activity\uff0c\u4ece\u800c\u5224\u65ad\u662f\u5426\u5b89\u88c5\u4e86\u67d0\u5e94\u7528\u3002<\/p>\n

\u8be5\u65b9\u6cd5\u8fd4\u56de\u7684\u662fResolveInfo\u5217\u8868\uff0c\u800cResolveInfo\u5305\u542b\u7684\u662fIntentFilter\u4fe1\u606f\u3002<\/p>\n

\u4ee5\u4e0b\u7ed3\u8bba\u90fd\u7ecf\u8fc7demo\u7684\u9a8c\u8bc1:<\/p>\n

    \n
  • \u6e05\u5355\u6587\u4ef6\u7684\u58f0\u660e\u4e2d\u5fc5\u987b\u5305\u542bIntentFilter\u4fe1\u606f\uff0cqueryIntentActivities\u65b9\u6cd5\u624d\u80fd\u67e5\u627e\u5230\u3002<\/li>\n
  • \n

    IntentFilter\u4e2d\u4e0d\u80fd\u5305\u542bdata\u4fe1\u606f\uff0c\u5982\u679c\u6709\u5b9a\u4e49\uff0c\u5219\u67e5\u627e\u4e0d\u5230\u4fe1\u606f\u4e86\uff0c\u8fde\u542f\u52a8\u7684Activity\u90fd\u627e\u4e0d\u5230\u3002\u8fd9\u91cc\u6682\u65f6\u6ca1\u6709\u53bb\u67e5\u770bThe Fucking Source Code\u3002<\/p>\n<\/li>\n

  • \n

    \u6dfb\u52a0 android:exported\u4e0e\u5426\u5bf9\u4e8e\u6b64\u65b9\u6cd5\u7684\u7ed3\u679c\u6ca1\u6709\u5f71\u54cd<\/p>\n<\/li>\n

  • \n

    \u5728\u534e\u4e3a\u7b49\u5bf9\u5e94\u7528\u5b89\u88c5\u5217\u8868\u6709\u6743\u9650\u63a7\u5236\u7684\u624b\u673a\u4e0a\uff0c\u91c7\u7528\u9690\u5f0f\u7684Intent\u83b7\u53d6\u4e0d\u5230\u6b63\u786e\u7684\u4fe1\u606f\uff0c\u5c31\u8fde\u6bcf\u4e2a\u5e94\u7528\u7684\u542f\u52a8Activity\u90fd\u83b7\u53d6\u4e0d\u5230\u3002<\/p>\n<\/li>\n

  • \n

    \u663e\u793a\u7684Intent\u5219\u4e0d\u53d7\u6743\u9650\u7684\u5f71\u54cd\uff0c\u5747\u53ef\u4ee5\u83b7\u53d6\u5230\u3002<\/p>\n<\/li>\n<\/ul>\n

    \u7ed3\u8bba<\/h2>\n
    \n

        \u91c7\u7528\u7b2c\u4e09\u79cd\u65b9\u6848\uff0c\u7528\u663e\u793a\u7684Intent(\u4e00\u822c\u6307\u5b9a\u5305\u540d\u6216\u8005\u7c7b\u540d)\u53bb\u67e5\u8be2\u662f\u5426\u5b89\u88c5\u4e86\u67d0\u5e94\u7528\u5728\u5404\u4e2a\u5382\u5546\u5404\u4e2a\u7cfb\u7edf\u7684\u624b\u673a\u4e0a\u662f\u53ef\u884c\u7684\uff0c\u4f46\u662f\u53ea\u80fd\u83b7\u53d6\u5230\u6307\u5b9a\u7684\uff0c\u800c\u4e0d\u662f\u5168\u90e8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Android \u5982\u4f55\u5b8c\u6574\u7684\u83b7\u53d6\u5230\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868\u83b7\u53d6\u7528\u6237\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868_android\u83b7\u53d6\u5df2\u5b89\u88c5\u5e94\u7528\u5217\u8868","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9199"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=9199"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9199\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=9199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=9199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=9199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}