ボタンを使用して通知しようとしていますが、通知と setLatestEventInfo の両方が非推奨です。
2 つのエラー:
1.コンストラクタ Notification(int, CharSequence, long) は非推奨ですNotification notify = new Notification(android.R.drawable.stat_notify_more, "Hello all", System.currentTimeMillis());
2.setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent)
タイプ Notification のメソッドは引数に適用されません(Context, CharSequence, CharSequence, Intent) notify.setLatestEventInfo(context, title, details, intent);
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotificationManager ns = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(android.R.drawable.stat_notify_more, "Hello all", System.currentTimeMillis());
Context context = MainActivity.this;
CharSequence title ="you have be notified";
CharSequence details = "Continue your work";
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
notify.setLatestEventInfo(context, title, details, intent);
ns.notify(0,notify);
}
});
}
API レベル:
android:minSdkVersion="11"
android:targetSdkVersion="17"
代替手段は何ですか?