「android入門」通知NotificationManager処理サンプルコード

1.INotificationManager
static private INotificationManager getService() {
if (sService != null) {
return sService;
}
sService = INotificationManager.Stub.asInterface(ServiceManager.getService(“notification"));
return sService;
}
2.Toastのshow()

/**
* 指定された期間にビューを表示.
*/
public void show() {
if (mNextView == null) {
throw new RuntimeException(“setViewが呼び出されていることが必要です);
}

INotificationManager service = getService();
String pkg = mContext.getPackageName();
TN tn = mTN;
tn.mNextView = mNextView;

try {
service.enqueueToast(pkg, tn, mDuration);
} catch (RemoteException e) {
// Empty
}
}
3.NotificatioManagerのnotify():
コード下記:
public void notify(String tag, int id, Notification notification)
{
int[] idOut = new int[1];
INotificationManager service = getService();
String pkg = mContext.getPackageName();
if (notification.sound != null) {
notification.sound = notification.sound.getCanonicalUri();
if (StrictMode.vmFileUriExposureEnabled()) {
notification.sound.checkFileUriExposed(“Notification.sound");
}
}
if (localLOGV) Log.v(TAG, pkg + “: notify(" + id + “, " + notification + “)");
try {
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
notification, idOut, UserHandle.myUserId());
if (id != idOut[0]) {
Log.w(TAG, “通知が壊れた:送信 " + id + “, got back " + idOut[0]);
}
} catch (RemoteException e) {
}
}

Android

Posted by arkgame