0

こんにちは、特定の時間にユーザーに通知を送信する必要があるアプリを開発しようとしています。インターネットでこのコードを見つけましたが、Eclipse は非推奨であると言っています。私のAPIでそれを行う適切な方法はどれですか? (16)

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

int icon = R.drawable.worldmap2;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText,when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
final Intent intent1 = new Intent(context, HttpExampleLimits.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent1, 0);
notification.setLatestEventInfo(context, contentTitle,contentText, pIntent);


nm.notify(1, notification);

どうもありがとうございました!

4

1 に答える 1

0

これを実現する最善の方法は、サポート ライブラリとNotificationCompatクラスを使用することです。

公式ドキュメントで多くの例を見つけることができます: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

于 2013-03-20T18:57:22.373 に答える