Android 앱을 개발 중이며 현재 알림을 작성하려고하는데 사용자가 알림을 클릭하면 활동이 시작됩니다. 알림은 잘 작성되었지만 활동이 시작되지 않았습니다.알림에서 활동 시작하기
다음은 알림 코드입니다.
private void showNotification(String username, String password)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager)context.getSystemService(ns);
CharSequence tickerText = "Username Copied";
long when = System.currentTimeMillis();
int icon = R.drawable.icon;
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "BPM - Login Management";
CharSequence contentText = "Username Copied";
Intent intentNotification = new Intent(context, CopyPassword.class);
intentNotification.setAction(Long.toString(when));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
intentNotification.putExtra("password", password);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentNotification, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int NOTIFICATION_ID = 1;
notificationManager.notify(NOTIFICATION_ID, notification);
}
차이점이있는 경우 안드로이드 활동이 아닌 일반 Java 클래스 내에서 알림이 생성됩니다.
도움 주셔서 감사합니다.
당신이이 일을하는 이유는 ... 'intentNotification.setAction (Long.toString (when));'? 'Intent'의 동작은'ACTION_VIEW'와 같아야합니다 (예를 들어). 동작을 현재 시스템 시간을 나타내는 임의의 값으로 설정하는 것은 의미가 없습니다. – Squonk
나는 내가 거기에서 무엇을하고 있었는지 단서가 없다. 나는 그것을 지금 제거했다. Intent.ACTION_VIEW를 사용하도록 변경했지만 차이가 없으며 완전히 제거해도 차이가 발생하지 않습니다. – Boardy
표시 할 코드는 브로드 캐스트 리시버 클래스 안에 있습니까? –