📄 incomingmessage.java
字号:
/* * Copyright (C) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.android.samples.app;import com.google.android.samples.R;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.content.Context;import android.content.Intent;import android.widget.Button;import android.widget.TextView;import android.os.Bundle;import android.view.View;import android.view.ViewInflate;public class IncomingMessage extends Activity { @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.incoming_message); Button button = (Button) findViewById(R.id.notify); button.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { performNotification(); } }); } protected void performNotification() { /* * Here we send a notification that is both transient and persistent. * The transient part is the view that comes up and shows the user * the text of what could be an incoming message. The persistent part * goes into the status bar where they can acknowledge it later. */ // look up the notification manager service NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // the transient notification ======================================= // create the view View view = inflateView(R.layout.incoming_message_panel); // set the text in the view TextView tv = (TextView)view.findViewById(R.id.message); tv.setText("kthx. meet u for dinner. cul8r"); // the persistent notification ====================================== // what happens when we click the icon Intent clickIntent = new Intent(Intent.MAIN_ACTION); clickIntent.setClass(this, IncomingMessageView.class); // construct the Notification object. Notification notif = new Notification( R.drawable.stat_sample, getText(R.string.status_bar_notification_title), clickIntent, null, null); // after a 100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms. notif.vibrate = new long[] { 100, 250, 100, 500}; // send the notification ============================================ nm.notifyWithView(R.layout.incoming_message_panel, view, NotificationManager.LENGTH_LONG, notif); } private View inflateView(int resource) { ViewInflate vi = (ViewInflate)getSystemService(Context.INFLATE_SERVICE); return vi.inflate(resource, null, null); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -