2012-06-26 4 views
1

상태 표시 줄의 내 알림에 두 개의 단추를 넣으 려합니다. 물론 사용자가 확장하기 전까지는 나타나지 않습니다. 내가 RemoteViews를 사용하여 내 알림에 대한 사용자 정의 레이아웃을 만들었지 만 현재 코드 구조로 인해 참조를 얻을 수 있는지 확실하지 않습니다.상태 알림에 단추 배치

@Override 
public void onMessage(Context context, Intent intent) { 
      Log.w("C2DMReceiver", 
      "Message Received, this is the message with no payload"); 
    Bundle extras = intent.getExtras(); 

    if (extras != null) { 
     String[] payload = new String[3]; 
     payload[0] = (String) extras.get("payload"); 
     payload[1] = (String) extras.get("payload2"); 
     SharedPreferences sharedP = Prefs.get(this); 
     boolean inApp = sharedP.getBoolean("currentlyInApp", true); 
     if (!inApp) { 
      createNotification(context, payload); 
     } 

    } 
} 

public void createNotification(Context context, String[] payload) { 
    SharedPreferences sharedP = Prefs.get(context); 
    boolean needsToLogin = sharedP 
      .getBoolean("loginFromNotification", true); 

    Log.w("C2DMReceiver", "createNotification called"); 

    NotificationManager notificationmanager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent notificationIntent = new Intent(this, WebViewActivity.class); 
    Intent notificationIntent2 = new Intent(this, UniteActivity.class); 
    PendingIntent pIntent; 
    if (needsToLogin) { 
     pIntent = PendingIntent.getActivity(this, 0, notificationIntent2, 
       PendingIntent.FLAG_CANCEL_CURRENT); 

    } else { 
     pIntent = PendingIntent.getActivity(this, 0, notificationIntent, 
       PendingIntent.FLAG_CANCEL_CURRENT); 
    } 

    // Compatibility builder 
    NotificationCompat.Builder notification = new NotificationCompat.Builder(
      context); 
    RemoteViews remote = new RemoteViews(getPackageName(),R.layout.notification); 


    //Button okButton = (Button) findViewById(R.layout.notification); 

    notification.setAutoCancel(false); 
    notification.setContent(remote); 
    notification.setContentIntent(pIntent); 
    notification.setWhen(System.currentTimeMillis()); 
    notification.setTicker(payload[0]); 
    notification.setSmallIcon(R.drawable.default1); 
    notification.setContentTitle(payload[1]); 
    notification.setContentText(payload[0]); 



    long duration[] = { 100, 300, 100 }; 
    notification.setVibrate(duration); 

    notificationmanager.notify(0, notification.getNotification()); 
} 

onMessage는 Google C2DM 라이브러리에서 가져온 방법으로 Google에서받은 인 텐트로 알림이 생성됩니다. 보기가 없으면 findViewById()를 사용하여 버튼에 대한 참조를 얻는 방법은 무엇입니까? 또는 다른 수단

답변

관련 문제