日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > 綜合技術(shù) > Notification用法

Notification用法

來源:程序員人生   發(fā)布時間:2015-01-24 09:15:49 閱讀次數(shù):3185次

本文介紹了Notification的用法。

1、示例演示用法

1)NotificationActivity.java

/** * 演示了Notification的用法 * Notification的創(chuàng)建、顯示、刪除 * 通知欄點擊Notification打開Activity、Service、Broadcast * 直接new1個Notification或通過Notification.Builder來創(chuàng)建 * 自定義Notification的視圖并點擊交互 */ public class NotificationActivity extends Activity { private BroadcastReceiver mBroadcastReceiver; private NotificationManager mNotificationManager; private int NOTIFICATION_ID = 0x007; private int NOTIFICATION_ID2 = 0x008; private int NOTIFICATION_ID3 = 0x009; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init(){ IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(NewBroadcastReceiver.ACTION_NOTIFICATION); intentFilter.addAction(NewBroadcastReceiver.ACTION_NOTIFICATION2); mBroadcastReceiver = new NewBroadcastReceiver(); registerReceiver(mBroadcastReceiver, intentFilter); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); findViewById(R.id.btn).setOnClickListener(mOnClickListener); findViewById(R.id.btn_direct).setOnClickListener(mOnClickListener); findViewById(R.id.btn_custom).setOnClickListener(mOnClickListener); //API level 11 Notification.Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher)//status bar .setTicker("猥瑣不")//status bar .setWhen(System.currentTimeMillis())//the time the event occurred .setDefaults(Notification.DEFAULT_SOUND) .setContentTitle("石鑫") .setContentText("小李飛刀") .setContentInfo("美好的回想") .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, NewActivity.class), 0))//startActivity // .setContentIntent(PendingIntent.getBroadcast(this, 0, // new Intent(NewBroadcastReceiver.ACTION_NOTIFICATION), 0))//sendBroadcastReceiver // .setContentIntent(PendingIntent.getService(this, 0, // new Intent(this, NewService.class), 0))//startService .setAutoCancel(true);//dismiss when touched Notification notification = builder.getNotification();//v16用build mNotificationManager.notify(NOTIFICATION_ID, notification); } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(mBroadcastReceiver); } private OnClickListener mOnClickListener = new OnClickListener() { @SuppressWarnings("deprecation") @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn: mNotificationManager.cancel(NOTIFICATION_ID);//通過ID刪除Notification mNotificationManager.cancel(NOTIFICATION_ID2); mNotificationManager.cancel(NOTIFICATION_ID3);break; case R.id.btn_direct: Notification notification = new Notification(R.drawable.ic_launcher, "monkey", System.currentTimeMillis()); //給Notification添加sound Uri ringURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notification.sound = ringURI; //給Notification添加Vibration long[] vibrate = new long[]{1000,1000,1000,1000,1000}; notification.vibrate = vibrate; notification.setLatestEventInfo(NotificationActivity.this, "Activity", "launch an activity", PendingIntent.getActivity(NotificationActivity.this, 0, new Intent(NotificationActivity.this, NewActivity.class), 0)); mNotificationManager.notify(NOTIFICATION_ID2, notification);break; case R.id.btn_custom: Notification notification2 = new Notification(R.drawable.ic_launcher, "monkey", System.currentTimeMillis()); RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.notification); notification2.contentView = remoteView; notification2.contentIntent = PendingIntent.getActivity(NotificationActivity.this, 0, new Intent(NotificationActivity.this, NewActivity.class), 0); notification2.contentView.setTextViewText(R.id.txt, "騷包"); notification2.contentView.setProgressBar(R.id.progressbar, 1000, 400, false); //注冊及在廣播中處理點擊事件 notification2.contentView.setOnClickPendingIntent(R.id.img, PendingIntent.getBroadcast(NotificationActivity.this, 0, new Intent(NewBroadcastReceiver.ACTION_NOTIFICATION2), 0)); mNotificationManager.notify(NOTIFICATION_ID3, notification2); default: break; } } }; }
2)activity_main.xml
<?xml version="1.0" encoding="utf⑻"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hit me" android:layout_gravity="center"/> <Button android:id="@+id/btn_direct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="direct" android:layout_gravity="center"/> <Button android:id="@+id/btn_custom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="custom" android:layout_gravity="center"/> </LinearLayout>
3)NewActivity.java
public class NewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { Log.i(getClass().getSimpleName(), "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_new); } }
4)activity_new.xml
<?xml version="1.0" encoding="utf⑻"?> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="歡迎步入星光大道"/> </RelativeLayout>
5)NewBroadcastReceiver.java
public class NewBroadcastReceiver extends BroadcastReceiver { /**使用4次,定義、注冊、發(fā)送、接收*/ public static final String ACTION_NOTIFICATION = "action.NOTIFICATION"; public static final String ACTION_NOTIFICATION2 = "action.NOTIFICATION2"; @Override public void onReceive(Context context, Intent intent) { if(ACTION_NOTIFICATION.equals(intent.getAction())){ Log.i(getClass().getSimpleName(), "onReceive"); }else if(ACTION_NOTIFICATION2.equals(intent.getAction())){ Toast.makeText(context, "輕點好嗎", Toast.LENGTH_SHORT).show(); } } }
6)NewService.java
public class NewService extends Service { @Override public IBinder onBind(Intent intent) { //只有Service.onBind(Intent)覆寫 return null; } @Override public void onCreate() { Log.i(getClass().getSimpleName(), "onCreate"); super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(getClass().getSimpleName(), "onStartCommand"); return super.onStartCommand(intent, flags, startId); } }
7)notification.xml
<?xml version="1.0" encoding="utf⑻"?> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:src="@drawable/ic_launcher"/> <TextView android:id="@+id/txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentTop="true"/> <ProgressBar android:id="@+id/progressbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/img" android:layout_alignParentBottom="true" style="@android:style/Widget.ProgressBar.Horizontal"/> </RelativeLayout>
8)AndroidManifest.xml
<?xml version="1.0" encoding="utf⑻"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.qinuli.notificationtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.VIBRATE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.qinuli.notificationtest.NotificationActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".NewActivity"></activity> <service android:name=".NewService"/> </application> </manifest>

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久成人在线 | 欧美三级电影在线观看 | 天天综合网网欲色 | 国产精品乱码久久久久久 | 国产乱码精品一区二区三区中文 | 国产精品久久久久久久久久新婚 | 欧美不卡在线 | 久久久久国产精品一区二区 | 午夜精品导航 | 国产免费黄色片 | 在线观看视频一区 | 欧美日韩精品免费观看 | 久久99精品久久久久久噜噜 | 久久九九免费 | 狠狠综合久久av一区二区老牛 | 日韩一区网站 | 亚洲三区视频 | 亚洲综合日韩欧美 | 国产精品99一区二区三区 | 99在线观看视频 | 一级黄色视| 国产精品视频一区二区三区不卡 | 操操操网 | 日韩精品视频免费在线观看 | 97久久超碰国产精品电影 | 麻豆视频免费在线播放 | 三级久久 | 一区二区三区精品在线 | 精品动漫一区二区 | 欧美日韩一区精品 | 婷婷欧美 | 精久久久久 | 激情综合五月天 | 99精品在线| 久久国产精品视频 | 操女人逼网站 | 国产91精品一区二区 | 欧美中文在线 | 亚洲成人中文字幕 | 久久精品2019中文字幕 | 日韩午夜精品 |