2012-06-26 3 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()? или какие-то другие средства

ответ

Смежные вопросы