第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

系統(tǒng)重新啟動(dòng)后,在廣播接收器中顯示警報(bào)對(duì)話框

系統(tǒng)重新啟動(dòng)后,在廣播接收器中顯示警報(bào)對(duì)話框

守著星空守著你 2019-12-13 17:10:00
美好的一天,在廣播接收機(jī)中,系統(tǒng)重新啟動(dòng)后,我試圖顯示一個(gè)警報(bào)對(duì)話框。我已經(jīng)在清單中添加了接收者并調(diào)用了所需的權(quán)限,但是在顯示對(duì)話框時(shí)出現(xiàn)錯(cuò)誤。請(qǐng)問我該如何正確實(shí)施呢?我的代碼:public void onReceive(final Context context, Intent intent) {    Log.d(TAG, "received boot completed broadcast receiver... starting settings");    String settings = context.getResources().getString(R.string.restart_setting);        String yes = context.getResources().getString(R.string.Settings);        String no = context.getResources().getString(R.string.Cancel);              final AlertDialog.Builder builder = new AlertDialog.Builder(context);                builder.setMessage(settings)                       .setCancelable(false)                       .setPositiveButton(yes, new DialogInterface.OnClickListener() {    public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id)    Intent config = new Intent(context, WeatherConfigure.class)     context.startActivity(config);    } })    .setNegativeButton(no, new DialogInterface.OnClickListener() {        public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {             dialog.cancel();        }    });  final AlertDialog alert = builder.create();  alert.show();    }正在收到此日志錯(cuò)誤:01-07 01:42:01.559: ERROR/AndroidRuntime(2004): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application01-07 01:42:01.559: ERROR/AndroidRuntime(2004): at android.view.ViewRoot.setView(ViewRoot.java:548)01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)01-07 01:42:01.559: ERROR/AndroidRuntime(2004): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at android.app.Dialog.show(Dialog.java:288)01-07 01:42:01.559: ERROR/AndroidRuntime(2004):at com.MuaaApps.MyWeatherUpdate.myWeatherBroadcastReceiver.onReceive(MyWeatherBroadcastReceiver.java:59)
查看完整描述

3 回答

?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以從此處獲取源代碼。

您不能直接從廣播接收器顯示對(duì)話框。您必須使用Activity。另外,為了接收ACTION_BOOT_COMPLETED您的活動(dòng),必須首先由用戶或其他應(yīng)用程序顯式啟動(dòng)(有關(guān)更多信息,Google應(yīng)用程序處于停止?fàn)顟B(tài))。

基本上,要實(shí)現(xiàn)所需的功能,您需要執(zhí)行以下操作:

  1. 創(chuàng)建顯示對(duì)話框的透明活動(dòng)。

  2. 創(chuàng)建BroadcastReceiver將接收ACTION_BOOT_COMPLETED并開始您的活動(dòng)。

  3. 在清單中注冊(cè)您的廣播接收器并獲得適當(dāng)?shù)脑S可。

此外,此問題提供有關(guān)如何創(chuàng)建透明活動(dòng)的更多信息。



查看完整回答
反對(duì) 回復(fù) 2019-12-14
  • 3 回答
  • 0 關(guān)注
  • 463 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)