2

(addAction을 사용하여) 사용자 정의 버튼으로 Jelly Bean 알림을 작성하는 데 도움이 필요합니다. 문제는 그저 작동시킬 수 없다는 것입니다. 기본적으로 다음 매개 변수를 사용하여 알림을 작성하려고합니다. 알림을 클릭하면 알림이 표시 될 때 실행중인 버튼 클릭 - 재생 - 일시 중지 플레이어에서 내 활동 중 하나를 가져와야합니다. 내 코드는 다음과 같습니다 수신기 :JellyBean에서 알림 - 동작이 작동하지 않습니다.

private BroadcastReceiver onNotification = new BroadcastReceiver() { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d("NOTIFICATION", "Received broadcast"); 
     Bundle extras = intent.getExtras(); 
     int state = extras.getInt("state"); 
     if (state == 1) { 
      playPauseMethod(); 
     } 

    } 

}; 

활동에서 onCreate 방법에서 내가 추가 한 :

IntentFilter notif_iff = new IntentFilter(
        MainService.NOTIF_BROADCAST); 
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
        onNotification, notif_iff); 

MainService의 코드는 다음입니다 : 그래서

public static final String ACTION = "com.formatbce.mdrive.action.UPDATE_UI"; 
public static final String NOTIF_BROADCAST = "com.formatbce.mdrive.action.NOTIF_BRD"; 
Intent in = new Intent(ACTION); 
Intent notifInt = new Intent(NOTIF_BROADCAST); 
private NotificationManager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

private void showNotification(final int statusBarIconID, 
     final int bigIconID, final int ppIconID, final String contentTitle, 
     final String contentText, final boolean showIconOnly) { 
    PendingIntent layoutIntent = PendingIntent.getActivity(this, 0, 
      new Intent(this, MediaFragmentActivity.class), 0); 

     int state = 1; 
     notifInt.setAction("blabla"); 
     notifInt.putExtra("state", state); 
     PendingIntent mIntent = PendingIntent.getBroadcast(
       getApplicationContext(), 0, notifInt, 
       PendingIntent.FLAG_UPDATE_CURRENT); 
     notification = new Notification.Builder(this) 
     .setContentTitle(contentTitle).setContentText(contentText) 
     .setSmallIcon(bigIconID).setContentIntent(layoutIntent) 
     .addAction(ppIconID, null, mIntent) 
     .build(); 
      notification.flags |= Notification.FLAG_ONGOING_EVENT; 
      mNM.notify(NOTIFICATION, notification); 
} 

, 내가 호출 할 때 showNotification() 메소드, 알림이 표시되고 몸체가 클릭되면 제대로 작동합니다. 내가, 아무것도 변경되지 않습니다 ... 내 말은, addAction와 함께 살고 있고 버튼을 클릭 해요 때 onReceive()에서 심지어 라인이 작동되지 않습니다

Log.d("NOTIFICATION", "Received broadcast"); 

은 여기에서 잘못 될 수 있는가? 엄청난 양의 설명서를 읽었지만 얻을 수는 없습니다. 누군가가 설명 할 수 있나요, 어떻게 작동시킬 수 있습니까? 감사합니다.

P. getActivity addAction PendingIntent 변경하면 잘 작동합니다 ...

+0

누군가? 적어도 저 기능을 이해하는 데 문제가 있습니까? 아니면 아무도 실제로 대답을 모르십니까? : – formatBCE

답변

0

나는 여기에 붙어있어 무엇 BroadcastReceiver 제대로 설치되어 있다고 생각합니다. 사실 BroadcastReceiver 대신에 Service를 사용하는 것이 좋습니다. BroadcastReceiver의 대기 시간 때문입니다 (동시에 큰일이 아닐 정도로 곧 발생해야합니다).

매니페스트에 BroadcastReceiver 설정이 올바르게 있습니까?

올바르게 작동하는지 확인하기 위해 BroadcastReceiver를 호출하는 활동을 만들 수 있습니까?

+0

답변을 주셔서 감사합니다.이 프로젝트는 이미 잊어 버렸지 만 주말에 픽업을 시도하겠습니다. – formatBCE

+0

브로드 캐스트 리시버를 자체 클래스에 넣고 매니페스트에 등록한 다음 액션을 수행하십시오. . 인라인 된 브로드 캐스트 리시버 선언이 시스템에 등록 된 방법 (확실한 지 모르겠다.) – Travis

+0

일반적으로 인라인 리시버가 매력처럼 작동한다는 것은 말할 필요가있다. 그러나 말했듯이, 나는 이것을 시도 할 것이다. 주말에, 고맙습니다. – formatBCE

관련 문제