2012-06-24 2 views
0

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 클래스 내에서 알림이 생성됩니다.

도움 주셔서 감사합니다.

+0

당신이이 일을하는 이유는 ... 'intentNotification.setAction (Long.toString (when));'? 'Intent'의 동작은'ACTION_VIEW'와 같아야합니다 (예를 들어). 동작을 현재 시스템 시간을 나타내는 임의의 값으로 설정하는 것은 의미가 없습니다. – Squonk

+0

나는 내가 거기에서 무엇을하고 있었는지 단서가 없다. 나는 그것을 지금 제거했다. Intent.ACTION_VIEW를 사용하도록 변경했지만 차이가 없으며 완전히 제거해도 차이가 발생하지 않습니다. – Boardy

+0

표시 할 코드는 브로드 캐스트 리시버 클래스 안에 있습니까? –

답변

2

setAction을 제거하면 필요하지 않습니다.

시도 :

Intent intentNotification = new Intent(context, CopyPassword.class); 
intentNotification.putExtra("password", password); 

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intentNotification, 0); 

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

는 또한 CopyPassword 활동을 보장하기가 귀하의 AndroidManifest를

에 선언 나는 그것에 대해 블로그 포스트를 작성했습니다 : http://blog.blundell-apps.com/notification-for-a-user-chosen-time/ - D

+0

Manifest 파일에 활동을 추가하는 것을 잊었 기 때문에 고마워했습니다. 나는 항상 그것에 대해 잊지 만 알림 때문에 활동을 시작하기 위해 로그 고양이에 예외를 던지지 않는 것 같습니다. – Boardy

관련 문제