基本信息
源码名称:串口触发连续消息弹出提示
源码大小:1.67M
文件格式:.rar
开发语言:Java
更新时间:2016-04-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
在一些情况下,需要不断地显示消息提示,本示例从串口输入广播命令来触发消息提示框的弹出,非常简单方便。

package com.example.noticedemo;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.widget.RemoteViews;

public class MainActivity extends Activity {

private static final String TAG = "zr_MainActivity";
Context mContext;
// public H mHandler = new H();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = MainActivity.this;
new H(mContext);
new NotificationCollectorService();
Log.d(TAG, "onCreate-----------");
}

// public void dataGet() {
//
// Log.d(TAG, "dataGet--------");
// NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
// // Notification myNotify = new Notification(R.drawable.message,   
// // "自定义通知:您有新短信息了,请注意查收!", System.currentTimeMillis());   
// Notification myNotify = new Notification();  
// myNotify.icon = R.drawable.ic_launcher;  
// myNotify.tickerText = "TickerText:您有新短消息,请注意查收!";  
// myNotify.when = System.currentTimeMillis();  
// myNotify.flags = Notification.FLAG_NO_CLEAR;// 不能够自动清除   
// RemoteViews rv = new RemoteViews(mContext.getPackageName(),  
// R.layout.my_notification);  
// rv.setTextViewText(R.id.text_content, "hello wrold!");  
// myNotify.contentView = rv;  
// Intent intent = new Intent(Intent.ACTION_MAIN);  
// PendingIntent contentIntent = PendingIntent.getActivity(mContext, 1,  
// intent, 1);  
// myNotify.contentIntent = contentIntent;  
// manager.notify(0, myNotify);
// }

class NotificationCollectorService extends NotificationListenerService {

@Override
public void onNotificationPosted(StatusBarNotification sbn) {

Log.d("zr_NotificationCollectorService", "open" "-----" sbn.toString());
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.d("zr_NotificationCollectorService", "shut" "-----" sbn.toString());

}
}
// class H extends Handler {
//
// public void handleMessage(Message msg) {
//
// switch (msg.what) {
//
// case 0: {
//
// dataGet();
// break;
// }
// default:
// break;
// }
// super.handleMessage(msg); 
// }
// }
}