В настоящее время я разрабатываю приложение для Android, в котором я создаю намерение уведомления, которое добавляет параметры в пакет намерений. При щелчке по уведомлению оно вызывает действие и получает данные из пакета. Однако при первом использовании приложение работает нормально, но когда вы нажимаете на другой элемент, предполагается, что оно передает разные данные в действие уведомления, но по какой-то причине оно не заменяет старые данные новыми.
Я пытался вызвать bundle.removeExtra ("companyPassword") перед тем, как использовать putExtra, но, похоже, это не имеет никакого значения. Ниже приведен код уведомления
private void notification(String companyName, String companyURL, String companyUsername, String loginPassword)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Click notification to copy password";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "PM - Login Management";
CharSequence contentText = "Click here to copy password";
Intent notificationIntent = new Intent(ShowLogins.this, DataManagement.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
notificationIntent.removeExtra("companyName");
notificationIntent.removeExtra("companyURL");
notificationIntent.removeExtra("companyUsername");
notificationIntent.removeExtra("companyPassword");
notificationIntent.putExtra("companyName", companyName);
notificationIntent.putExtra("companyURL", companyURL);
notificationIntent.putExtra("companyUsername", companyUsername);
notificationIntent.putExtra("companyPassword", loginPassword);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int NOTIFICATION_ID = 1;
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(NOTIFICATION_ID, notification);
finish();
. Ниже приведен код для действия уведомления, в котором он извлекает данные, которые передаются в пакет
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
// setContentView(R.layout.data_mangement);
Bundle bundle = this.getIntent().getExtras();
company = bundle.getString("companyName");
companyURL = bundle.getString("companyURL");
username = bundle.getString("companyUsername");
password = bundle.getString("companyPassword");
bundle.clear();
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
Encryption encryption = new Encryption();
String decryptedPassword = encryption.decrypt(password);
clipboard.setText(decryptedPassword);
toastNotification("Password Successfully Copied\n\nPaste into password field");
bundle.clear();
finish();
moveTaskToBack(true);
} catch (Exception ex) {
Log.d("DataManagement Error", ex.toString());
}
}
. По какой-то причине, когда вызывается действие для уведомления, оно возвращает только данные который был впервые отправлен при первом выборе элемента вместо получения новых данных.
Спасибо за любую помощь, которую вы можете оказать.