2012-08-31 3 views
6

setOnClick 보류중인 인 텐트를 사용하여 코드를 편집했으며이 코드는 ImageView 및 알림 텍스트를 원하는대로 분리하여 작동하지만 여전히 도움이 필요합니다.Android에서 원격보기가있는 사용자 정의 알림

내 서비스 클래스에서 미디어 플레이어를 일시 중지하거나 재생하려면 알림 보류 의도에서 서비스 중지 또는 재생 방법에 어떻게 액세스 할 수 있습니까?

일부 사람들은 방송 수신기가 도움이 될 것이라고 말하지만 정확히 어떻게 작동하는지 알 수는 없습니다. 알림에서 일시 중지 버튼으로 웹 브라우저를 열 수 있었지만 서비스 방법에 액세스하는 방법을 모르겠습니다. 가지고 있다면 샘플 코드를 공유하십시오.

@SuppressWarnings("deprecation") 
void showNotification() { 
    int pendingRequestCode = 0; 
     int pendingFlag = 0; 

     final Resources res = getResources(); 
     final NotificationManager notificationManager = (NotificationManager) getSystemService(
       NOTIFICATION_SERVICE); 
     Intent intent = new Intent(this,MainActivity.class); 
     PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0); 
     Notification.Builder builder = new Notification.Builder(this) 
       .setSmallIcon(R.drawable.ic_action_search) 
       .setAutoCancel(true) 
       .setTicker("this is notification") 
       .setContentIntent(pi); 


     // Sets a custom content view for the notification, including an image button. 
     RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification); 
     layout.setTextViewText(R.id.notification_title, getString(R.string.app_name)); 
     Intent clickIntent = new Intent(Intent.ACTION_VIEW, Uri_myBlog); 
     PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),pendingRequestCode, clickIntent, pendingFlag); 
     layout.setOnClickPendingIntent(R.id.notification_button,pendingIntent); 
     builder.setContent(layout); 

     // Notifications in Android 3.0 now have a standard mechanism for displaying large 
     // bitmaps such as contact avatars. Here, we load an example image and resize it to the 
     // appropriate size for large bitmaps in notifications. 
     Bitmap largeIconTemp = BitmapFactory.decodeResource(res, 
       R.drawable.pause); 
     Bitmap largeIcon = Bitmap.createScaledBitmap(
       largeIconTemp, 
       res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width), 
       res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), 
       false); 
     largeIconTemp.recycle(); 

     builder.setLargeIcon(largeIcon); 

     notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification()); 
    } 

    PendingIntent getDialogPendingIntent(String dialogText) { 
     return PendingIntent.getActivity(
       this, 
       dialogText.hashCode(), // Otherwise previous PendingIntents with the same 
             // requestCode may be overwritten. 
       new Intent(ACTION_DIALOG) 
         .putExtra(Intent.EXTRA_TEXT, dialogText) 
         .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 
       0); 
    } 
+0

를 확인하실 수 있습니다 것은 내게 재생을 제어하는 ​​리모트 뷰를 사용하여 알림 큰 뷰를 구축 할 수 있습니다. 제안을 제공합니다 /이 링크 (http://stackoverflow.com/questions/14508369/how-to-create-a처럼 일시 정지 -notification-similar-to-play-music-app-from-google) 모든 것이 옳다. 그러나 내가 device back button을 클릭했을 때 그리고 applicat 이온 클릭 이벤트 (재생/일시 정지/앞으로/닫기) 버튼이 작동하지 않습니다. 제발 도와주세요. –

답변

6

당신은 당신이 목표로 안드로이드의 버전을 말하지 않았지만, 일반적으로는 Android 3.x (허니 콤)까지 할 수 없습니다. 그래서 2.x에서 그런 일이 일어나기를 원한다면, 미안해 - 너는 운이 없어.

허니 콤의 경우 사용자 정의 레이아웃을 제공하고 setOnClickPendingIntent()을 호출하여 필요한 각 버튼에 PendingIntent을 할당하기 만하면됩니다. 당신은 SDK의 샘플을 다운로드있어 경우에, 또한 당신을 http://developer.android.com/guide/components/bound-services.html

메신저 를 사용하여. XX 14 (또는 그 이상)에서 아무것도입니다. HoneycombGallery 응용 프로그램의 MainActivity가 (당신의 <SDK>\samples\android-XX\HoneycombGallery\ 폴더에 있어야한다 참조

+0

내 표적은 분 2.2 ~ 4.1 ... froyo는이 기능을 지원하지 않을 것입니다.하지만 honeycomb 및 jellybean 사용자는 내 앱에서 사용할 수 있습니다. 이 기능을 안내해주세요 –

+0

편집 된 답변보기 –

+0

안드로이드 API 번호를 확인하고 그에 따라 2.2 이하의 정상적인 알림 스타일과 2.3 이상의 버튼 알림을 변경할 수 있습니다. –