通知用のアンドロイド用の小さなアプリを作成しています。
ただし、通知クラス エラーでエラーが発生します (11 または 16 でサポートされている API レベル)。次に、 NotificationCompat クラスを使用してみましたが、リソースをタイプに解決できないことが示されていますimport package import android.support.v4.app.NotificationCompat.Builder;
つまり、Notification クラスを使用すると API レベルのエラーが発生し、NotificationCompat を使用するとそのリソース エラーが発生します。これらの両方のエラーを解決するにはどうすればよいですか?
public void createNotification(View view) {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Context context=new Context();
// Build notification
// Actions are just fake
NotificationCompat.Builder noti = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + "star.ankit90@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.addAction(R.drawable.ic_launcher, "Call", pIntent)
.addAction(R.drawable.ic_launcher, "More", pIntent)
.addAction(R.drawable.ic_launcher, "And more", pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}