2015-11-07 118 views
0

我正在製作一個應用程序,它具有此報警功能。我想要的是當警報觸發時,會出現一個對話框(在應用程序內部或外部)。我是android新手。我試着讀一些關於它的消息來源,我非常困惑。如何顯示報警對話框android

btw,我已經完成了如何設置鬧鐘。

我沒有設置警報等問題我的問題是在警報觸發時進行對話。

你能幫我嗎?

+2

見http://stackoverflow.com/questions/4459058/alarm-manager-example – scrayne

+0

我已經知道如何設置鬧鐘,廣播接收器等。我的問題是,當鬧鐘觸發時,我無法顯示對話框。 – Ruby

回答

0

當您的警報觸發而不是通話活動時,您必須進行透明活動,並根據需要進行對話框佈局。 您可以使用AlarmManager和廣播接收器創建鬧鐘。

+0

如何做到透明的活動和對話?我可以製造警報。 – Ruby

+0

嘗試使用此樣式http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android並在活動中創建對話框佈局 –

0

更換吐司與對話(http://developer.android.com/guide/topics/ui/dialogs.html

public void onReceive(Context context, Intent intent) 
{ 
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); 
    wl.acquire(); 

    // Put here YOUR code. 
    Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For example 

    wl.release(); 
} 
0

在這裏,下面的代碼是建立一個對話框代碼:

AlertDialog.Builder builder1 = new AlertDialog.Builder(context); 
     builder1.setMessage("Write your message here."); 
     builder1.setCancelable(true); 
     builder1.setPositiveButton("Yes", 
       new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.cancel(); 
      } 
     }); 
     builder1.setNegativeButton("No", 
       new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.cancel(); 
      } 
     }); 

     AlertDialog alert11 = builder1.create(); 
     alert11.show();