編輯:關於Android編程
編寫了一個Notification通知工具類,裡面含有監聽系統清除通知欄方法,焦點在加粗斜體部分:
public class Notifier {
private static final String TAG = Notifier.class.getSimpleName();
private static Notifier instance;
private Context mContext;
private static final int NOTIFICATION_ID_1 = 0;
private static final int NOTIFICATION_ID_2 = 1;
private static final int NOTIFICATION_ID_3 = 2;
private static final int NOTIFICATION_ID_4 = 3;
private static final int NOTIFICATION_ID_5 = 4;
private static final int NOTIFICATION_ID_6 = 5;
private static final int NOTIFICATION_ID_7 = 6;
private static final int NOTIFICATION_ID_8 = 7;
public static Notifier getInstance(Context context) {
if (instance == null) {
instance = new Notifier(context);
}
return instance;
}
public Notifier(Context context) {
mContext = context;
}
public NotificationManager getNotificationManager(Context context) {
return (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
}
public void showNotify(Context context, int largeIcon, int smallIcon,
CharSequence tickerText, CharSequence contentInfo,
CharSequence contentTitle, CharSequence contentText) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
largeIcon);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
// notifyBuilder.setLargeIcon(bitmap);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setContentInfo(contentInfo);
notifyBuilder.setContentTitle(contentTitle);
notifyBuilder.setContentText(contentText);
notifyBuilder.setAutoCancel(false);
notifyBuilder.setWhen(System.currentTimeMillis());
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
notifyBuilder.setContentIntent(contentIntent);
Notification noti = notifyBuilder.build();
getNotificationManager(context).notify(NOTIFICATION_ID_1, noti);
}
public void showCustomViewNotify(Context context, int smallIcon,
CharSequence tickerText, int layoutId) {
RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(),
layoutId);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setContent(mRemoteViews);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setOngoing(true);
notifyBuilder.setAutoCancel(true);
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
notifyBuilder.setContentIntent(contentIntent);
Notification noti = notifyBuilder.build();
Intent dismissedIntent = new Intent(
"com.xxxx.android.notify.dismissed");
/**
* The intent to execute when the notification is explicitly dismissed
* by the user, either with the "Clear All" button or by swiping it away
* individually.
*
* This probably shouldn't be launching an activity since several of
* those will be sent at the same time.
*/
noti.deleteIntent = PendingIntent.getBroadcast(context, 0,
dismissedIntent, 0);
getNotificationManager(context).notify(NOTIFICATION_ID_2, noti);
}
public Notification getForegroundServiceNotify(Context context,
int smallIcon, CharSequence tickerText, CharSequence contentInfo,
CharSequence contentTitle, CharSequence contentText) {
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class), 0);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(
context);
notifyBuilder.setSmallIcon(smallIcon);
notifyBuilder.setTicker(tickerText);
notifyBuilder.setContentInfo(contentInfo);
notifyBuilder.setContentTitle(contentTitle);
notifyBuilder.setContentText(contentText);
notifyBuilder.setAutoCancel(false);
notifyBuilder.setContentIntent(contentIntent);
// notifyBuilder.setWhen(System.currentTimeMillis());
notifyBuilder.setDefaults(Notification.DEFAULT_ALL);
return notifyBuilder.build();
}
}
1. 前言 在Android開發中,如果是一些簡單的布局,都很容易搞定,但是一旦涉及到復雜的頁面,特別是為了兼容小屏手機而使用了ScrollView以後,就會出
ExpandableListView介紹 ExpandableListView的引入 ExpandableListView可以顯示一個視圖垂直滾動顯示
1.在移動設備訪問m.alipay.com時,如果本地安裝了支付寶客戶端,則浏覽器會調用本地客戶端,沒有安裝則會跳轉到下載頁面,提示安裝。剛好有這樣的需求,就分析了下支付
先看看效果:實現代碼:public class ScrollBanner extends LinearLayout { private TextView mBanner