1
我試圖在用戶單擊電源按鈕時顯示我的菜單。我正在使用禁用系統電源按鈕微調菜單的代碼,但我不想在每個活動中編寫此代碼。如何調用這個服務來禁用應用程序級別的系統對話框?如何在應用程序級別調用Intent.ACTION_CLOSE_SYSTEM_DIALOGS
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("Focus debug", "Focus changed !");
if (!hasFocus) {
Log.d("Focus debug", "Lost focus !");
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
}
}
/* I don't want to write above code on each activity */
import android.widget.Toast;
public class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
public void onReceive(final Context context, final Intent intent) {
// Log.i("HERE", "------------------------------------HERE");
// Toast.makeText(context, "OFFFFFFFFFFFFFFFF",Toast.LENGTH_LONG).show();
}
}
<receiver
android:name="com.eurosoft.cabtreasure.receiver.CloseSystemDialogsIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.CLOSE_SYSTEM_DIALOGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
給我,請例如我 – user3341546
已經活動延伸基地活動如何添加的android如果您的活動已經擴展了BaseActivity,則將其擴展爲 – user3341546
,然後將此方法移動到您的BaseActivity類中:public void onWindowFocusChanged(boolean hasFocus){...} – donfuxx