public class Settings extends AppCompatActivity {
CheckBox cb1;
NotificationManager manager;
Notification myNotication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
cb1=(CheckBox) findViewById(R.id.notificationchk);
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);// anything here and above seems ok(no error)
cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)//"this" taskstackbuilder cannot be applied to oncheckedlistener
.Builder(mContext)//the mcontext is not working
.setContentTitle("New mail from ")
.setContentText("i")
.setSmallIcon(R.drawable.ic_launcher)
.build();Intent resultIntent = new Intent(this, firstpage.class);//everything inside bracket underlined red
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);//"this" taskstackbuilder cannot be applied to oncheckedlistener
stackBuilder.addParentStack(Settings.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);//cannot resolve symbol mBuilder
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());//cannot resolve symbol mID,mBuilder
}//all errors marked
});//basically this,mbuilder,mID,mContext problem
私はJavaとAndroidアプリケーションの開発に慣れていません。私は何時間もインターネットを検索して通知とチェックボックスを一緒に働かせ、最終的には失敗しました。 あなたのすばらしい答えをありがとう:Dチェックボックスをオンにしたときに通知を送信する方法は?
Sir、(1).setSmallIconを変更すると、必要なandroid.support.v7.app.NotificationCompat.Builderがandroid.app.notificationを見つけました。 (3)そして、私が最初のページであることを意図していればどうでしょうか?設定ではなく、ジャバ? - Ze Qian Mok 1時間前 –
インテントはすでにfirstpage.javaです。インテントでは、2つのパラメータを指定します。最初は呼び出しアクティビティ、その後は着陸アクティビティです。 "Intent resultIntent =新しいインテント(Settings.this、firstpage.class); 'その意図が設定から最初のページにあることを意味します。 setsmalliconについては、すでに設定しています。エラーが表示されている場合は、上から通知のインポートをクリアし、正しいパッケージを使用して再度インポートしてください –