① 安卓開機廣播是什麼意思
就是android 系統開機的時候會發送一個廣播,應用程序注冊的這個廣播的話就可以收到,通常很多應用就會啟動後台服務
② android系統啟動一個應用時有什麼廣播
現在有應用A和應用B,我需要在A應用中啟動B應用中的某個Activity
實現:A應用中的Activity發送廣播,關鍵代碼如下:
String broadcastIntent = "com.example.android.notepad.NotesList";//自己自定義
Intent intent = new Intent(broadcastIntent);
this.sendBroadcast(intent);
B應用中需要一個BroadcastReceiver來接收廣播,取名TestReceiver繼承BroadcastReceiver重寫onReceive方法啟動一個activity,關鍵代碼如下:
if(intent.getAction().equals("com.example.android.notepad.NotesList")){
Intent noteList = new Intent(context,NotesList.class);
noteList.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(noteList);
}
到這代碼就完成了,當然在AndroidManifest.xml中要對TestReceiver進行注冊,代碼如下:
<receiver android:name="TestReceiver">
<intent-filter>
<action android:name="com.example.android.notepad.NotesList"/>
</intent-filter>
</receiver>
這樣就完成了通過廣播啟動另一個應用Activity。
注意問題:Context中有一個startActivity方法,Activity繼承自Context,重載了startActivity方法。如果使用 Activity的startActivity方法,不會有任何限制,而如果使用Context的startActivity方法的話,就需要開啟一個新的task,解決辦法是,加一個flag,也就是這句noteList.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);的作用。如果不添加這句,就會報android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity,Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
分類: Android
③ Android啟動廣播時怎樣往廣播中傳遞參數
在android中使用廣播來讓其他監聽廣播的地方能夠對相應的事情做處理,但有的時候需要傳遞一些其他的附帶值,而這個時候是可以直接用播放廣播的intent來傳遞的。
例:
Intent intent = new Intent();
intent.putExtra("msgPersons", msgPersons);
intent.setAction(Constant.hasMsgUpdatedAction);
intent.putExtra("userId", userId);
intent.putExtra("msgCount", messages.size());
sendBroadcast(intent);
④ android一個activity啟動時會向系統發送一個默認廣播嗎android.intent.category.LAUNCHER這個是廣播嗎
你要捕捉的話,自己寫一個廣播發送。有兩個方法,一個是動態注冊(就是需要是注冊發送),一個是靜態的。
想監聽的話,就是應用程序啟動的時候發送廣播。用service接受。我是這樣做的。類是音樂播放器,在退出應用它還會繼續播放。當再次點開始不影響播放,而且播放器上面的進度條和歌詞都是更新過的時時改變。
⑤ Android手機無開機廣播,應用如何自啟
三星部分手機支持自啟動功能,(以三星S7 Edge為例)設置應用程序自啟動方法:智能管理器-應用程序管理-管理自動運行-滑動應用程序開關。
⑥ android接受不到開機廣播
intent
判斷
intent.getAction()是否與
android.intent.action.BOOT_COMPLETED
相同,發出的是這個,你沒監聽這個Action
。
另外注意的是,如果是
3.1以下的系統,沒問題。3.1以上的系統,需要有Activity存在,並且啟動一次程序,才能夠實現廣播。
⑦ Android開機過程中什麼時候發開機廣播
Android開機過程中發開機廣播如下: intent的發送點是在: finishBooting函數(ActivityManagerService.java) 調用關系是: startHomeActivityLocked() -> ensureBootCompleted() -> finishBooting() -> mStackSupervisor.startHomeActivity(intent, aInfo) 所以系統發出這個intent的時候 ,home界面並沒有起來,發出之後很短的時間 home就啟動,在配置文件AndroidManifest.xml中向系統注冊receiver,子節點 intent-filter 表示接收android.intent.action.BOOT_COMPLETED 消息 <receiver android:name="com.ray.ray.receiver.BootCompletedReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
⑧ android 啟動一個app是否有廣播
這是一個有深度的問題。
博文「Android 編程下監視應用程序的啟動」,如果它是准確的,那麼啟動app系統並不會提供廣播。
⑨ android 接受開機廣播
Android接收開機廣播,需要用到播廣播接收者BroadcastReceiver組件。
具體代碼:
在配置文件AndroidManifest.xml中向系統注冊receiver
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
需要添加相應許可權
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
在Receiver中就可以添加開機需要進行的操作
public class BootCompletedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
}
}