Notification

package com.example.fdvasdasfaf;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
public class HelloBroadcastReceiver extends BroadcastReceiver{
private NotificationManager notificationManager = null;
private Context context;
int count = 0; //有时service会发出多条通知,我们用一个计数器来模拟不同的通知
private static final int NOTIFY_ME_ID=1337; //通知管理器通过通知ID来标识不同的通知,创建和删除通知是需要提供通知号。
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("0");
this.context=context;
showNotification(intent);
}
private void showNotification(Intent intent) {
count ++;
Resources res =context.getResources();
notificationManager=
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("showNormal").setContentInfo("contentInfo")
.setContentTitle("ContentTitle").setContentText("ContentText")
.setNumber(count)
.setContentIntent(pendingIntent)
.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL)
.build();
notificationManager.notify(NOTIFY_ME_ID, notification);
}

public void notifyClear( ){
notificationManager.cancel( NOTIFY_ME_ID );
}

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

package com.example.fdvasdasfaf;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class CdlRegisterActivity extends Activity {

private Context mContext;

private Button btnSendBroadcast;
private TextView etBroadcastContent;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.register_page);
mContext=this;
btnSendBroadcast= (Button)findViewById(R.id.btn_sendbroadcast);

btnSendBroadcast.setOnClickListener(new SendBroadcastClickListener() );
etBroadcastContent=(TextView) findViewById(R.id.et_broadcastContent);

}
@Override
protected void onSaveInstanceState( Bundle outState){
super.onSaveInstanceState(outState);
}
private class SendBroadcastClickListener implements OnClickListener{


@Override
public void onClick(View arg0) {

String content=etBroadcastContent.getText().toString().trim();

if(content.length()<1){
Toast.makeText(mContext, etBroadcastContent.getHint(), 1).show();
return ;
}
// TODO Auto-generated method stub

Intent intent=new Intent();
intent.setAction("android.intent.action.HelloBroadcastTest");
intent.putExtra("content",content);
sendBroadcast(intent);
}

}


}

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

<receiver android:name=".HelloBroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.HelloBroadcastTest" />
</intent-filter>
</receiver>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值