Reputation: 65
I'm implementing a simple notification for my app.
The notification system works, but if I set the vibrate it crush.
private void sendNotification(HashMap notifica) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.waiter_ico)
.setContentTitle((CharSequence) notifica.get("title"))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText((CharSequence) notifica.get("text")))
.setContentText((CharSequence) notifica.get("text"));
mBuilder.setVibrate(pattern);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
if I comment
//mBuilder.setVibrate(pattern);
it perfectly works.
Thanks for the help.
Upvotes: 0
Views: 204
Reputation: 38098
You need to set the VIBRATE permission in your AndroidManifest.xml file:
<uses-permission android:name="android.permission.VIBRATE"/>
Of course, it won't vibrate in the emulator, only on a real device.
But it won't do no harm.
Upvotes: 3
Reputation: 2053
you need to add permission
android.permission.VIBRATE
it will work fine with some versions of android but it's create problem with 4.1.
Thanks
Upvotes: 2