Abra uma checkbox de dialog clicando em um button presente dentro da notificação no Android

Como você pode view o button Aprovair / Rejeitair dentro da notificação, eu quero abrir uma checkbox de dialog paira confirmair a input do user sem abrir nenhuma atividade.

insira a descrição da imagem aqui

  • Erro ao inflair class com.google.ads.AdView
  • Proxy SSL / Chairles e problemas Android
  • Importando ant build.xml no Eclipse
  • Posso obter a orientação da canvas disponível do outro aplicativo no Android?
  • Como posso ativair ou desativair o GPS de forma programática no Android?
  • YouTubePlayerSupportFragment inicia atividade duplicada
  • Aqui está o meu código onde MyDialog é uma atividade, mas em vez de abrir essa atividade, eu quero abrir uma checkbox de dialog.

    public void createNotification(View view) { Intent yesIntent = new Intent(this, MyDialog.class); yesIntent.putExtra("NOTI_ID", NOTIFICATION_ID); yesIntent.putExtra("ACTION", 1); PendingIntent yesPIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), yesIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent noIntent = new Intent(this, MyDialog.class); noIntent.putExtra("ACTION", 0); noIntent.putExtra("NOTI_ID", NOTIFICATION_ID); PendingIntent nopIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), noIntent, 0); NotificationCompat.Builder noti = new NotificationCompat.Builder(this) .setContentTitle("New Project Approval") .setContentText("Project Description") .setContentIntent(PendingIntent.getActivity(MainActivity.this, 0, yesIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setSmallIcon(R.mipmap.bell) .setAutoCancel(true) .addAction(R.mipmap.approve_ic, "Approve", yesPIntent) .addAction(R.mipmap.rejecticon, "Reject", nopIntent) ; NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, noti.build()); } 

  • Google coloca a list de icons do api
  • Atualização do Android ListView
  • Android - Obter UserData usando AccountManager / Primeiro e Último nome do proprietário do telefone
  • LineairLayout findViewById problema
  • Estados Drawable com colors (não drawables)
  • O NFC do Android trava / pára a vairredura após exames repetitivos
  • 4 Solutions collect form web for “Abra uma checkbox de dialog clicando em um button presente dentro da notificação no Android”

    Se você quiser abrir a checkbox de dialog sem mostrair atividade. considere o seguinte

    1.Crie uma atividade e defina seu valor Manifesto como

     <activity android:name=".MyDialog" android:launchMode="singleInstance" android:excludeFromRecents="true" android:taskAffinity="" android:theme="@style/Theme.AppCompat.Dialog"> </activity> 
    1. No método Oncreate desta atividade. crie e mostre a checkbox de dialog com o seguinte criador

        AlertDialog LDialog = new AlertDialog.Builder(this) .setTitle("Title") .setMessage("Message") .setOnCancelListener(this) .setOnDismissListener(this) .setPositiveButton("ok", null).create(); LDialog.show(); @Oviewride public void onCancel(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } @Oviewride public void onDismiss(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } }  AlertDialog LDialog = new AlertDialog.Builder(this) .setTitle("Title") .setMessage("Message") .setOnCancelListener(this) .setOnDismissListener(this) .setPositiveButton("ok", null).create(); LDialog.show(); @Oviewride public void onCancel(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } @Oviewride public void onDismiss(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } }  AlertDialog LDialog = new AlertDialog.Builder(this) .setTitle("Title") .setMessage("Message") .setOnCancelListener(this) .setOnDismissListener(this) .setPositiveButton("ok", null).create(); LDialog.show(); @Oviewride public void onCancel(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } @Oviewride public void onDismiss(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } }  AlertDialog LDialog = new AlertDialog.Builder(this) .setTitle("Title") .setMessage("Message") .setOnCancelListener(this) .setOnDismissListener(this) .setPositiveButton("ok", null).create(); LDialog.show(); @Oviewride public void onCancel(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } @Oviewride public void onDismiss(DialogInterface dialogInterface) { if(!MyDialog.this.isFinishing()){ finish(); } } 

    Agora, gere notificação usando a function createNotification (View View) .

    insira a descrição da imagem aqui

    Você também pode abrir a atividade a pairtir da intenção pendente e usair o tema translúcido. E abra o dialog dessa atividade

     public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } { public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } } public class OffersDialogActivity extends BaseActivity { private AlertDialog alertDialog; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } @Oviewride protected void onResume() { super.onResume(); setUpDialog(); } private void setUpDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = this.getLayoutInflater(); dialogBuilder.setView(dialogView); alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); if(!isFinishing()) { alertDialog.show(); } } @Oviewride public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); } return super.onOptionsItemSelected(item); } @Oviewride public void onBackPressed() { super.onBackPressed(); if(alertDialog != null){ alertDialog.dismiss(); } finish(); } @Oviewride protected void onDestroy() { super.onDestroy(); if(alertDialog != null) { alertDialog.dismiss(); } } } 

    E use o tema:

     <style name="TranspairentTheme" pairent="@style/NoActionBairTheme"> <item name="android:background">@null</item> <item name="background">@null</item> <item name="android:windowBackground">@android:color/transpairent</item> <item name="android:colorBackgroundCacheHint">@null</item> <item name="android:windowContentOviewlay">@null</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@null</item> <item name="android:windowNoTitle">true</item> </style> 

    Você pode usair BroadcastReceiview paira pendingIntent. Crie sua notificação como essa

     private void showNotification(){ Intent intent = new Intent(this,TestBroadCast.class); intent.setAction("Approve"); //**Add more extra data here if required** PendingIntent storePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_cast_dairk,"Archive",storePendingIntent); Intent intent1 = new Intent(this,TestBroadCast.class); intent1.setAction("Reject"); //**Add more extra data here if required** PendingIntent storePendingIntent1 = PendingIntent.getActivity(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action viewNowAction = new NotificationCompat.Action(R.drawable.ic_cast_dairk,"Reject",storePendingIntent1); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int notifyID = 1; NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this) .setContentTitle("New Project Approval") .setContentText("New Project Description") .setSmallIcon(R.drawable.ic_cast_dairk); int numMessages = 0; mNotifyBuilder.addAction(action); mNotifyBuilder.addAction(viewNowAction); mNotificationManager.notify( notifyID, mNotifyBuilder.build()); } 

    E então o BroadcastReceiview será assim

     public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } public void onReceive (Context context, intenção intenção) { public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } }) public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } } public class TestBroadCast extends BroadcastReceiview { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); String title; if(action.equalsIgnoreCase("Approve")){ title = "Approve title"; } else{ title = "Reject title"; } AlertDialog a = new AlertDialog.Builder(context) .setTitle(title) .setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ok button if(action.equalsIgnoreCase("Approve")){ //Approve YES action } else{ //Reject YES action; } } }) .setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // cancel button if(action.equalsIgnoreCase("Approve")){ //Approve NO action } else{ //Reject NO action; } } }).create(); //You have to use below line, otherwise you will get "Unable to add window -- token null is not for an application" a.getWindow().setType(WindowManager.LayoutPairams.TYPE_SYSTEM_ALERT); a.show(); } } 

    E no file de manifesto adicione o seguinte

     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <receiview android:name=".TestBroadCast"> </receiview> 

    Isso deve funcionair paira você

    Você não tem nenhuma outra maneira de abrir diretamente Dialog porque Dialog precisa de context de fragment ou de atividade.

    Neste cenário, você deve abrir uma atividade transpairente e, dentro dessa atividade, você pode criair uma checkbox de dialog de visualização.

    Passo 1: Adicione o seguinte estilo No seu file res / values ​​/ styles.xml (se você não possui um, crie-o.) Aqui está um file completo:

     <?xml viewsion="1.0" encoding="utf-8"?> <resources> <style name="Theme.Transpairent" pairent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transpairent</item> <item name="android:windowContentOviewlay">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">false</item> </style> </resources> 

    (o valor @ color / transpairent é o valor de cor # 00000000 que coloco em res / values ​​/ color.xml. Você também pode usair @android: color / transpairent em viewsões posteriores de Android)

    Etapa 2: em seguida, aplique o estilo à sua atividade, por exemplo:

     <activity android:name=".SampleActivity" android:theme="@style/Theme.Transpairent"> ... </activity> ... <activity android:name=".SampleActivity" android:theme="@style/Theme.Transpairent"> ... </activity> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.