2012-08-31 13 views
6

मैंने setOnClick लंबित इरादे का उपयोग करके कोड संपादित किया है, और यह कोड ImageView और अधिसूचना पाठ अलग-अलग के लिए काम करता है, लेकिन मुझे अभी भी कुछ मदद चाहिए।एंड्रॉइड पर रिमोट व्यू के साथ कस्टम अधिसूचना

मैं अपनी सेवा कक्षा से मध्यस्थता को रोकना या खेलना चाहता हूं, तो मैं अधिसूचना लंबित मंशा से सेवा के स्टॉप या प्ले विधि को कैसे एक्सेस कर सकता हूं?

कुछ कहते हैं कि प्रसारण रिसीवर आपकी मदद करेंगे, लेकिन मुझे यह नहीं पता कि यह कैसे काम करेगा। मैंने अधिसूचना से विराम बटन से एक वेब ब्राउज़र खोलने में कामयाब रहा है, लेकिन मुझे नहीं पता कि सेवा विधियों तक कैसे पहुंचना है। यदि आपके पास कुछ नमूना कोड साझा करें।

@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 -नोटिफिकेशन-समान-टू-प्ले-संगीत-ऐप-से-google) सभी सही हैं लेकिन जब मैं डिवाइस बैक बटन पर क्लिक करता हूं और आवेदक से बाहर जाता हूं आयन क्लिक इवेंट (प्ले/पॉज़/फॉरवर्ड/क्लोज़) बटन काम नहीं करता है। कृपया मेरी मदद करें। –

उत्तर

6

आप नहीं बताया Android का कौनसा संस्करण आप लक्षित है, लेकिन सामान्य रूप में यह जब तक Android 3.x (Honeycomb) संभव नहीं है। तो यदि आप 2.x पर ऐसा करना चाहते हैं, तो क्षमा करें - आप भाग्य से बाहर हैं।

हनीकॉम के लिए, आपको बस एक कस्टम लेआउट प्रदान करना होगा और setOnClickPendingIntent() पर कॉल करके आपको आवश्यक प्रत्येक बटन पर PendingIntent असाइन करना होगा। आप एसडीके के नमूने डाउनलोड किया गया है, तो देखने के HoneycombGallery अनुप्रयोग के MainActivity (अपने <SDK>\samples\android-XX\HoneycombGallery\ फ़ोल्डर में होगी। XX 14 (या अधिक) से कुछ भी है।

+0

मेरा लक्ष्य न्यूनतम 2.2 से 4.1 है ... ठीक है कि फ्रोयो इस सुविधा का समर्थन नहीं करेगा .. लेकिन हनीकॉम और जेलीबीन उपयोगकर्ता इसे मेरे ऐप में उपयोग कर सकते हैं कृपया मुझे इस विशेषताओं के लिए मार्गदर्शन करें –

+0

संपादित उत्तर –

+0

कोई तरीका है एंड्रॉइड एपीआई नंबर की जांच करें और इसके अनुसार मैं 2.2 से कम के लिए सामान्य और मेरी अधिसूचना शैली को 2.3 और ऊपर –

संबंधित मुद्दे