here is my java file
public class two extends Fragment {
EditText ed1, ed2, ed3;
public two() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_two, container, false);
ed1 = (EditText) view.findViewById(R.id.editText);
ed2 = (EditText) view.findViewById(R.id.editText2);
ed3 = (EditText) view.findViewById(R.id.editText3);
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_two, container, false);
}
public void sendNotification(View v){
String Name = ed1.getText().toString().trim();
String Tittle = ed2.getText().toString().trim();
String Question = ed3.getText().toString().trim();
NotificationManager notif = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification.Builder(getActivity().getApplicationContext()).
setContentText(Question).
setContentTitle(Tittle + "-" + Name).
setSmallIcon(R.drawable.map).build();
notif.notify(0,n);
}
}
the build() on the second to the last line showing error don't know why please what do I have to do thank you
You can Try This..
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification Title")
.setContentText("Notification Content")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setShowWhen(true)
.setChannelId(channelId)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(YOUR_NOTIFICATION_ID, mBuilder.build());
Here I Used NotificationCompat
instead of Notification
You can Give any integer value to YOUR_NOTIFICATION_ID
and string value to channelId
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.