2016-08-20 2 views
0

여기 통지를 내 코드입니다 : -알림 버튼에 작업을 추가하는 방법은 무엇입니까?

여기
public void showNotification(String Name, String Rate, int Image_Source, int PandP, int Repeat) { 

    RemoteViews remoteview = new RemoteViews(getPackageName(), R.layout.notification_layout); 

    PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SongsListActivity.class), 0); 
    notification = new NotificationCompat.Builder(this) 
      .setContent(remoteview) 
      .setPriority(2) 
      .setTicker(NameD.getText()) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle(NameD.getText()) 
      .setContentText(RateD.getText()) 
      .setContentIntent(pi) 
      .setAutoCancel(false) 
      .setCustomBigContentView(remoteview) 
      .build(); 

    notification.bigContentView = remoteview; 
    remoteview.setImageViewResource(R.id.Repeat_N, Repeat); 
    remoteview.setImageViewResource(R.id.P_and_P_N, PandP); 
    remoteview.setTextViewText(R.id.Name_N, Name); 
    remoteview.setTextViewText(R.id.Rate_N, Rate); 
    remoteview.setImageViewResource(R.id.Image_N, Image_Source); 
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(111111, notification); 
} 

통지의 내 XML입니다 - 내 통보

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#2196F3"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:background="#2196F3" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/Image_N" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     tools:ignore="ContentDescription" /> 

    <LinearLayout 
     android:id="@+id/text_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/Name_N" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="bottom" 
      android:textAppearance="?android:textAppearanceMedium" 
      android:textColor="@android:color/white" 
      android:textStyle="bold" 
      android:maxLength="25"/> 

     <TextView 
      android:id="@+id/Rate_N" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:gravity="top" 
      android:textAppearance="?android:textAppearanceMedium" 
      android:textColor="#F44336" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

      <ImageButton 
       android:id="@+id/Repeat_N" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@drawable/ic_repeat_white_48dp" 
       android:background="#2196F3"/> 

      <ImageButton 
       android:id="@+id/Previous_N" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@drawable/ic_skip_previous_white_48dp" 
       android:background="#2196F3"/> 

      <ImageButton 
       android:id="@+id/P_and_P_N" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@drawable/ic_play_arrow_white_48dp" 
       android:background="#2196F3"/> 

      <ImageButton 
       android:id="@+id/Next_N" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@drawable/ic_skip_next_white_48dp" 
       android:background="#2196F3"/> 


     </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 

레이아웃

이제 알림의 4 버튼에 작업을 추가하면 어떻게됩니까? -

a) MediaPlayer 미디어 플레이어를 일시 중지 한 다음 이미지를 재생하도록 변경합니다.

b) 다음 및 이전 Imagebuttons이 방법 MediaPlayer를 호출 (I)

c) 상기 Repet하여 ImageButton 원격보기로 수신기를 추가하는 방법 changeRepeat()

+0

http://stackoverflow.com/questions/21925688/adding-button-action-in-custom-notification 어쩌면이 도움이 u – Tony

+0

참조하십시오 : http : //stackoverflow.com/questions/15350998/determine-addaction-click -for-android-notifications – KrishnaJ

답변

0

전화 int로

remoteViews.setOnClickPendingIntent(R.id.someView, pendingIntent); 
+0

좋아, 내가 노래를 일시 중지하는 내 버튼에 대해 말한 내용을 추가했다고 가정 해 보겠습니다. 지금 보류중인 인 텐트는 무엇을합니까? –

+0

일시 중지 버튼을 클릭하면 보류중인 인 텐트가 트리거됩니다. 보류중인 인 텐트가 수신자 또는 서비스를 시작하거나 보류중인 인 텐트 인스턴스를 얻는 방법에 따라 활동이 달라질 수 있습니다. 자세한 정보 : https://developer.android.com/reference/android/app/PendingIntent.html –

0

remoteViews.setOnClickPendingIntent(R.id.someView, pendingIntent);을 BroadCastReceiver와 조합하여 사용하고 다음과 같이 건물 신고를 할 수 있습니다.

BroadCast 리시버 트리거 방식으로 미디어 플레이어를 관리해야합니다. 제 경우에는 MainActivity에 바인딩 된 서비스가 있으므로 MainActivity의 메소드가 서비스를 관리 할 때 인터페이스를 통해 메인 및 브로드 캐스트 리시버를 연결했습니다. 서비스는 MediaPlayer를 관리합니다.

관련 문제