6

सबसे पहले मैं उन सभी लिंक देख लिया है:कंपन सब से

लेकिन मैं हिल मेरे फोन हासिल नहीं कर सकते जब मैं एक पुश अधिसूचना प्राप्त करें। यहाँ मेरी कोड है:

PushReceiver

public class PushReceiver extends FirebaseMessagingService { 
    public PushReceiver() { 
    } 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     if(remoteMessage.getData() != null){ 
      Map<String, String> data = remoteMessage.getData(); 
      sendNotification(data.get("message")); 
     } 
     else{ 
      if(remoteMessage.getNotification() != null) { 
       sendNotification(remoteMessage.getNotification().getBody()); 
      } 
     } 
    } 

    private void sendNotification(String messageBody) { 
     Intent intent = new Intent(this, BaseActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
       PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_done_all_24dp) 
       .setContentTitle(getString(R.string.str_notification_order_ready)) 
       .setContentText(messageBody) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

     notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 


     notificationManager.notify(ConstantUtils.NOTIFICATION_ID_ORDER_READY, notificationBuilder.build()); 
    } 
} 

अनुमति

<uses-permission android:name="android.permission.VIBRATE"/> 

परीक्षण

डिवाइस: नेक्सस 5

Android संस्करण: 6.0.1

वहाँ है कि मैं यह काम करने के लिए क्या करना चाहिए अज्ञात टोना किसी तरह का है?

+0

आप इस अतः [समाधान] जाँच करना चाहते हो सकता है (http://stackoverflow.com/a/36869888/5995040) या है [इस] (http://stackoverflow.com/a/33951000/5995040)। यह आपकी समस्या को हल करने में आपकी मदद कर सकता है। –

+0

@ श्री रेबोट मुझे जवाब देने में देरी के लिए खेद है, लेकिन उन समाधानों में से कोई भी मेरे लिए काम नहीं करता! :( – guisantogui

उत्तर

9

आप भी अपनी NotificationCompat.Builder उदाहरण आप प्रणाली ध्वनि डिफ़ॉल्ट, कंपन और के लिए रोशनी प्रदान करता है जो करने के लिए setDefaults (int defaults) उपयोग कर सकते हैं अपने अधिसूचना। DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS: |()

मूल्य एक या बिटवाइज़-या के साथ संयुक्त निम्नलिखित क्षेत्रों के और अधिक होना चाहिए।

सभी डिफ़ॉल्ट मानों के लिए, DEFAULT_ALL का उपयोग करें।

पूर्व। अपने कोड के अनुसार यदि आप डिफ़ॉल्ट ध्वनि सेट कर रहे हैं तो, आप डिफ़ॉल्ट ध्वनि सेट करना चाहते हैं और कंपन करता है, तो:

notificationBuilder.setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE); 

आप सभी डिफ़ॉल्ट सेटिंग चाहते हैं, आप इसे notificationBuilder.setDefaults(-1) की स्थापना करके प्राप्त कर सकते हैं, यह DEFAULT_ALL मूल्य के रूप में विचार करें।

सेटडिफॉल्ट के लिए एंड्रॉइड doc देखें।

संपादित करें:

कंपन 1000 एमएस की देरी है। यदि आप पहले एक को 0 पर सेट करते हैं, तो यह तुरंत बंद हो जाएगा।यह एक {देरी, कंपन, नींद, कंपन, सो} पैटर्न

// Each element then alternates between delay, vibrate, sleep, vibrate, sleep 
notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000}); 
0

यह फोन कंपन:

Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); 
// Vibrate for 500 milliseconds 
v.vibrate(500); 

जब आप फोन अधिसूचना भी फोन इस

+0

मैन मेरे पास मेरी सेवा के अंदर कोई एमसीएन्टेक्स्ट नहीं है, लेकिन मैं इसके बिना getSystemService पर कॉल कर सकता हूं, हालांकि, यह कंपन नहीं रखता है :( – guisantogui

+0

mContext संदर्भ है, आप इसके बजाय 'getActivity()' का उपयोग कर सकते हैं –

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