2
我正在做一個通知視圖項目。通知欄上會出現通知,當我點擊通知欄時,它會繼續下一個活動,以顯示與通知內容相同的信息。但得到這個錯誤...E /表面:getSlotFromBufferLocked:未知的緩衝區:0xb96ae9c0得到這個錯誤
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb96ae9c0
我的代碼是
MainActivity.java
public class MainActivity extends AppCompatActivity {
Button view_notifi,btn_time,btn_date;
int notificationID,getHour,getMin,getDay,getMonth,getYear;
final int dialogTime=0,dialogDate=1;
Notification notification;
EditText edt_heading,edt_details,edt_details2;
String head,details,details2;
String Time,setDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt_heading=(EditText)findViewById(R.id.editText_Heading);
edt_details=(EditText)findViewById(R.id.editText_Details);
edt_details2=(EditText)findViewById(R.id.editText_details2);
notificationID=1;
view_notifi=(Button)findViewById(R.id.button_viewN);
btn_time=(Button)findViewById(R.id.button_time);
btn_date=(Button)findViewById(R.id.button_date);
view_notifi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
head=edt_heading.getText().toString();
details=edt_details.getText().toString();
details2=edt_details2.getText().toString();
displayNotification(head,details,details2);
edt_heading.getText().clear();
edt_details.getText().clear();
edt_details2.getText().clear();
}
});
}
public void getTimeInfo(View view){
showDialog(dialogTime);
}
public void getDateInfo(View view){
showDialog(dialogDate);
}
protected Dialog onCreateDialog(int id){
switch (id){
case dialogTime:
return new TimePickerDialog(this,mTimeListener,getHour,getMin,false);
case dialogDate:
DatePickerDialog dialog = new DatePickerDialog(this, mDateListener, getYear, getMonth, getDay);
DatePicker datePicker = dialog.getDatePicker();
Calendar calendar = Calendar.getInstance();
datePicker.setMinDate(calendar.getTimeInMillis());
//dialog.getDatePicker().setMinDate(new Date().getTime());
return dialog;
//return new DatePickerDialog(this,mDateListener,getYear,getMonth,getDay);
}
return null;
}
private TimePickerDialog.OnTimeSetListener mTimeListener=new TimePickerDialog.OnTimeSetListener(){
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
getHour=hourOfDay; getMin=minute;
Time=String.valueOf(" "+getHour+":"+getMin);
Toast.makeText(getBaseContext(),"Time: "+Time,Toast.LENGTH_SHORT).show();
}
};
private DatePickerDialog.OnDateSetListener mDateListener=new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
getYear=year; getMonth=monthOfYear+1;getDay=dayOfMonth;
//getMonth=+1;
setDate=String.valueOf(" "+getDay+"/"+getMonth+"/"+getYear);
Toast.makeText(getBaseContext(),"Date: "+setDate,Toast.LENGTH_SHORT).show();
}
};
public void displayNotification(String str1,String str2,String str3){
Intent intent = new Intent("notify_filter");
Bundle bundle = new Bundle();
bundle.putString("arg1", str1);
bundle.putString("arg2", str2);
bundle.putString("arg3", str3);
bundle.putString("arg4", Time);
bundle.putString("arg5", setDate);
intent.putExtras(bundle);
intent.putExtra("notificationID",notificationID);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification.Builder builder = new Notification.Builder(MainActivity.this);
builder.setAutoCancel(true);
builder.setTicker("New Alert...");
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(str1);
builder.setContentText(str2);
builder.setSubText("Time " + Time + " Date:" + setDate); //API level 16
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
builder.setNumber(100);
builder.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification = builder.getNotification();
notification.vibrate = new long[]{100, 250, 100, 400};
notificationManager.notify(notificationID, notification);
}
}
ViewNotification.java
public class ViewNotification extends AppCompatActivity {
TextView head,detail1,detail2,time,date;
Bundle bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_notification);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(getIntent().getExtras().getInt("notificationID"));
head=(TextView)findViewById(R.id.textView_head);
detail1=(TextView)findViewById(R.id.textView_det1);
detail2=(TextView)findViewById(R.id.textView_det2);
time=(TextView)findViewById(R.id.textView_time);
date=(TextView)findViewById(R.id.textView_date);
bundle = getIntent().getExtras();
String view1= bundle.getString("arg1");
String view2= bundle.getString("arg2");
String view3= bundle.getString("arg3");
//String view4=bundle.getString("arg4");
//String view5=bundle.getString("arg5");
head.setText(view1);
detail1.setText(view2);
detail2.setText(view3);
time.setText(bundle.getChar("arg4"));
date.setText(bundle.getChar("arg5"));
}
}