{"rsdb":{"rid":"309024","subhead":"","postdate":"0","aid":"224186","fid":"118","uid":"1","topic":"1","content":"
\n\t\t\t\t\t\t\t\t\n \t\t\t\t\t\t\t\t \n\t\t\t\t\t\t
\n \n

\u95ee\u9898\uff1a\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u53ef\u4ee5\u5728\u5b89\u88c5\u540e\u81ea\u542f\u52a8\uff0c\u6ca1\u6709ui\u7684\u7eafservice\u5e94\u7528\u5982\u4f55\u542f\u52a8\uff1f<\/span><\/p>\n

1\u3001Android\u5e94\u7528\u5982\u4f55\u5f00\u673a\u81ea\u542f\u52a8<\/span><\/p>\n

(1)\u3001\u5728AndroidManifest.xml\u4e2d\u6ce8\u518cAndroidManifest.xml\u4e2d\u6ce8\u518cBOOT_COMPLETED Action \u6ce8\u610f\u4e0d\u4ec5\u8981\u6dfb\u52a0android.intent.action.BOOT_COMPLETED\u5bf9\u5e94\u7684action\uff0c\u8fd8\u9700\u8981\u6dfb\u52a0\u5bf9\u5e94\u7684uses-permission<\/span><\/p>\n

(2)\u3001Receiver\u63a5\u6536\u5e7f\u64ad\u8fdb\u884c\u5904\u7406<\/span><\/p>\n

<\/p>

public class BootBroadcastReceiver extends BroadcastReceiver {\n  public static final String TAG = \"BootBroadcastReceiver\";\n  @Override\n  public void onReceive(Context context, Intent intent) {\n<span style=\"white-space:pre\">\t<\/span>String action = intent.getAction().toString();\n<span style=\"white-space:pre\">\t<\/span>if (action.equals(Intent.ACTION\\_BOOT\\_COMPLETED)) {\n<span style=\"white-space:pre\">\t<\/span>  \/\/ u can start your service here\n<span style=\"white-space:pre\">\t<\/span>  Toast.makeText(context, \"boot completed action has got\", Toast.LENGTH_LONG).show();\n<span style=\"white-space:pre\">\t<\/span>   return;\n<span style=\"white-space:pre\">\t<\/span>}\n  }\n}<\/code><\/pre>

2\u3001\u81ea\u542f\u52a8\u5931\u8d25\u7684\u539f\u56e0<\/span><\/p>\n

\u63a5\u6536\u4e0d\u5230BOOT_COMPLETED\u5e7f\u64ad\u53ef\u80fd\u7684\u539f\u56e0<\/span><\/p>\n

(1)\u3001BOOT_COMPLETED\u5bf9\u5e94\u7684action\u548cuses-permission\u6ca1\u6709\u4e00\u8d77\u6dfb\u52a0<\/span><\/p>\n

(2)\u3001\u5e94\u7528\u5b89\u88c5\u5230\u4e86sd\u5361\u5185\uff0c\u5b89\u88c5\u5728sd\u5361\u5185\u7684\u5e94\u7528\u662f\u6536\u4e0d\u5230BOOT_COMPLETED\u5e7f\u64ad\u7684<\/span><\/p>\n

(3)\u3001\u7cfb\u7edf\u5f00\u542f\u4e86Fast Boot\u6a21\u5f0f\uff0c\u8fd9\u79cd\u6a21\u5f0f\u4e0b\u7cfb\u7edf\u542f\u52a8\u5e76\u4e0d\u4f1a\u53d1\u9001BOOT_COMPLETED\u5e7f\u64ad<\/span><\/p>\n

(4)\u3001\u5e94\u7528\u7a0b\u5e8f\u5b89\u88c5\u540e\u91cd\u6765\u6ca1\u6709\u542f\u52a8\u8fc7\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5e94\u7528\u7a0b\u5e8f\u63a5\u6536\u4e0d\u5230\u4efb\u4f55\u5e7f\u64ad\uff0c\u5305\u62ecBOOT_COMPLETED\u3001ACTION_PACKAGE_ADDED\u3001CONNECTIVITY_ACTION\u7b49\u7b49\u3002<\/span><\/p>\n

Android3.1\u4e4b\u540e\uff0c\u7cfb\u7edf\u4e3a\u4e86\u52a0\u5f3a\u4e86\u5b89\u5168\u6027\u63a7\u5236\uff0c\u5e94\u7528\u7a0b\u5e8f\u5b89\u88c5\u540e\u6216\u662f(\u8bbe\u7f6e)\u5e94\u7528\u7ba1\u7406\u4e2d\u88ab\u5f3a\u5236\u5173\u95ed\u540e\u5904\u4e8estopped\u72b6\u6001\uff0c\u5728\u8fd9\u79cd\u72b6\u6001\u4e0b\u63a5\u6536\u4e0d\u5230\u4efb\u4f55\u5e7f\u64ad\u3002\u76f4\u5230\u88ab\u542f\u52a8\u8fc7(\u7528\u6237\u6253\u5f00\u6216\u662f\u5176\u4ed6\u5e94\u7528\u8c03\u7528)\u624d\u4f1a\u8131\u79bb\u8fd9\u79cd\u72b6\u6001\uff0c\u6240\u4ee5Android3.1\u4e4b\u540e(1)\u3001\u5e94\u7528\u7a0b\u5e8f\u65e0\u6cd5\u5728\u5b89\u88c5\u540e\u81ea\u5df1\u542f\u52a8 (2)\u3001\u6ca1\u6709ui\u7684\u7a0b\u5e8f\u5fc5\u987b\u901a\u8fc7\u5176\u4ed6\u5e94\u7528\u6fc0\u6d3b\u624d\u80fd\u542f\u52a8\uff0c\u5982\u5b83\u7684Activity\u3001Service\u3001Content\n Provider\u88ab\u5176\u4ed6\u5e94\u7528\u8c03\u7528\u3002 \u5b58\u5728\u4e00\u79cd\u4f8b\u5916\uff0c\u5c31\u662f\u5e94\u7528\u7a0b\u5e8f\u88abadb push you.apk \/system\/app\/\u4e0b\u662f\u4f1a\u81ea\u52a8\u542f\u52a8\u7684\uff0c\u4e0d\u5904\u4e8estopped\u72b6\u6001\u3002<\/span><\/p>\n


<\/span><\/p>\n

3\u3001adb\u53d1\u9001BOOT_COMPLETED<\/span><\/p>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc71adb shell am broadcast -a android.intent.action.BOOT_COMPLETED \u547d\u4ee4\u53d1\u9001BOOT_COMPLETED\u5e7f\u64ad\uff0c\u800c\u4e0d\u7528\u91cd\u542f\u6d4b\u8bd5\u673a\u6216\u6a21\u62df\u5668\u6765\u6d4b\u8bd5BOOT_COMPLETED\u5e7f\u64ad\uff0c\u8fd9\u6761\u547d\u4ee4\u53ef\u4ee5\u66f4\u7cbe\u786e\u7684\u53d1\u9001\u5230\u67d0\u4e2apackage\uff0c\u5982\u4e0b\uff1aadb\n shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name\/class_name<\/span><\/p>\n


<\/span><\/p>\n

\u8f6c\u81ea\uff1a http:\/\/www.trinea.cn\/android\/android-boot_completed-not-work\/<\/span><\/p>\n <\/div>\n <\/div>","orderid":"0","title":"Android\u5e94\u7528\u5982\u4f55\u5f00\u673a\u81ea\u542f\u52a8\u3001\u81ea\u542f\u52a8\u5931\u8d25\u539f\u56e0","smalltitle":"","mid":"0","fname":"HBase","special_id":"0","bak_id":"0","info":"0","hits":"486","pages":"1","comments":"0","posttime":"2019-05-15 01:52:15","list":"1557856335","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Android<\/A> \u5e94\u7528<\/A> \u5982\u4f55<\/A> \u5f00\u673a<\/A> \u542f\u52a8<\/A> \u5931\u8d25<\/A> \u539f\u56e0<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";s:4:\"head\";s:0:\"\";}","target":"0","ip":"47.106.78.186","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":" \u95ee\u9898\uff1a\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u53ef\u4ee5\u5728\u5b89\u88c5\u540e\u81ea\u542f\u52a8\uff0c\u6ca1\u6709ui\u7684\u7eafservice\u5e94\u7528\u5982\u4f55\u542f\u52a8\uff1f1\u3001Android\u5e94\u7528\u5982\u4f55\u5f00\u673a\u81ea\u542f\u52a8(1)\u3001\u5728AndroidManifest.xml\u4e2d\u6ce8\u518cAndroidManifest.xml\u4e2d\u6ce8\u518cBOOT_COMPLETED Action \u6ce8\u610f\u4e0d\u4ec5\u8981\u6dfb\u52a0android.intent.action..","lastview":"1719085387","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}