Notification + Dialog, notificationdialog
For more information, see http://blog.csdn.net/harryweasley/article/details/42168079. thank you.
We know that users may not start the Android app again after downloading it, so I have done this function to remind users to start the app again.
Of course, the premise for this function is that you have to have a service running in the background and ensure that the service will not be killed by the system.
I have used two methods to do this function. The first is to use icationicationmanager, and the second is to use AlertDialog to automatically open the screen and display it on the desktop background.
Let's take a look at it first:
The background is the desktop background, which is set in the configuration file.
Use icationicationmanager:
Private void notification () {icationicationmanager nm; Notification not; nm = (icationicationmanager) getSystemService (Context. NOTIFICATION_SERVICE); not = new Notification (R. drawable. ic_launcher, "opening the worship reminder", System. currentTimeMillis (); // accompanied by the system default sound not. defaults | = Notification. DEFAULT_SOUND; // with default flashlight not. defaults | = Notification. DEFAULT_LIGHTS; // click this notification in the notification bar and the notification not is automatically cleared. flags | = Notification. FLAG_AUTO_CANCEL; // notification bar Title CharSequence contentTitle = ""; // The notification bar content CharSequence contentText = "Please open the! "; // ActivityIntent notificationIntent = new Intent (this, LuncherActivity. class); PendingIntent contentIntent = PendingIntent. getActivity (this, 0, icationicationintent, 0); not. setLatestEventInfo (this, contentTitle, contentText, contentIntent); // pass the Notification to icationicationmanagernm. notify (0, not );}
Use the bullet box mode:
Jump intent
Intent alert = new Intent(this, AlertDialogActivity.class);alert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);this.startActivity(alert);
Alert. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_NO_USER_ACTION );
Code under AlertDialogActivity
Package com. bcinfo. pray. ui. activity; import com. bcinfo. pray. r; import com. bcinfo. pray. clock. set. alarms; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. window; import android. view. windowManager; import android. view. view. onClickListener; import android. widget. textView; public class AlertDialogActivity extends Activity {@ Overrid Eprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // set final Window win = getWindow (); win. addFlags (WindowManager. layoutParams. FLAG_SHOW_WHEN_LOCKED | WindowManager. layoutParams. FLAG_DISMISS_KEYGUARD); // Turn on the screen unless we are being launched from the AlarmAlert // subclass. if (! GetIntent (). getBooleanExtra ("screen_off", false) {win. addFlags (WindowManager. layoutParams. FLAG_KEEP_SCREEN_ON | WindowManager. layoutParams. FLAG_TURN_SCREEN_ON | WindowManager. layoutParams. FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);} setContentView (R. layout. alarm_alert2); findViewById (R. id. dismiss ). setOnClickListener (new OnClickListener () {public void onClick (View v) {finish () ;}}); TextView snooze = (TextView) findViewById (R. id. snooze); snooze. requestFocus (); snooze. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {startActivity (new Intent (AlertDialogActivity. this, LuncherActivity. class); finish ();}});}}
The code in alarm_alert2 is
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: gravity = "center"> <LinearLayout android: id = "@ + id/id_policy_dialog" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_gravity = "center" android: layout_marginLeft = "20dip" android: layout_marginRight = "20dip" androi D: background = "# ffffffff" android: gravity = "center_horizontal" android: orientation = "vertical"> <RelativeLayout android: id = "@ + id/id_polic_part" android: layout_width = "fill_parent" android: background = "@ color/white" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/alertTitle" style = "? Android: attr/textAppearanceMedium "android: layout_width =" fill_parent "android: layout_height =" 40dip "android: background =" @ drawable/top_corner_bg "android: ellipsize =" end "android: gravity = "center" android: padding = "5dip" android: singleLine = "true" android: text = "Reminder"/> <TextView android: id = "@ + id/id_pray_des" style = "? Android: attr/plugin "android: layout_width =" fill_parent "android: layout_height =" wrap_content "android: layout_below =" @ id/alertTitle "android: layout_marginLeft =" 20dip "android: layout_marginRight = "20dip" android: gravity = "left" android: paddingTop = "30dp" android: paddingBottom = "30dip" android: text = "Please open the prayer reminder again, "android: textColor =" @ color/text_black "/> <ImageView android: id =" @ + id/id _ Pray_over_flag "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_marginRight =" 10dip "android: layout_marginTop =" 10dip "android: true" android: authorization = "true" android: src = "@ drawable/icon_pray_over" android: visibility = "gone"/> </RelativeLayout> <RelativeLayout android: layout_width = "fill_parent" android: layout_height = "42dip" Android: layout_marginTop = "0dip"> <TextView android: layout_width = "fill_parent" android: layout_height = "1dip" android: layout_alignParentTop = "true" android: background = "@ color/set_edge"/> <TextView android: layout_width = "1dip" android: layout_height = "fill_parent" android: layout_centerInParent = "true" android: background = "@ color/set_edge"/> <LinearLayout android: layout_width = "fill_parent" android: layout _ Height = "fill_parent" android: orientation = "horizontal"> <TextView android: id = "@ + id/snooze" style = "? Android: attr/textAppearanceMedium "android: layout_width =" fill_parent "android: layout_height =" fill_parent "android: layout_weight =" 1 "android: gravity =" center "android: text = "OK" android: textColor = "@ color/title_color"/> <TextView android: id = "@ + id/dismiss" style = "? Android: attr/textAppearanceMedium "android: layout_width =" fill_parent "android: layout_height =" fill_parent "android: layout_weight =" 1 "android: gravity =" center "android: text = "Disable" android: textColor = "@ color/title_color"/> </LinearLayout> </RelativeLayout> </LinearLayout>
Under the configuration file
<activity android:name=".ui.activity.AlertDialogActivity" android:theme="@android:style/Theme.Wallpaper.NoTitleBar" />
Android: theme = "@ android: style/Theme. Wallpaper. NoTitleBar" indicates that the background of AlertDialogActivity is the background of the mobile phone Wallpaper.
Remember to add permissions
<uses-permission android:name="android.permission.WRITE_SETTINGS" /><uses-permission android:name="android.permission.WAKE_LOCK" />
For more information about icationicationmanager, click here to view the http://www.cnblogs.com/jerrychoi/archive/2010/05/28/1746221.html