English 中文(简体)
通知不健全或无效?
原标题:Notification not making sound or vibration?

我正在拟定一个方案,我要通知我。 当通知过期时,只展示标语。 无声或振动或光。

我的法典就是这方面的一个例子:

int icon = R.drawable.icon;  
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

Context context = getApplicationContext();      

CharSequence contentTitle = "My notification";  
CharSequence contentText = "Countdown Complete!";

Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon, myCountDown.getName() + " is completed!", System.currentTimeMillis());

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
notificationManager.notify(myCountDown.getId(), notification);
问题回答

添加通知灯,请添加(注意到滞后者,而不是违约者):

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB=0xffffffff; //color, in this case, white
notification.ledOnMS=1000; //light on in milliseconds
notification.ledOffMS=4000; //light off in milliseconds

对缺省而言,

notification.defaults |= Notification.DEFAULT_SOUND;

缺省振动模式:

notification.defaults |= Notification.DEFAULT_VIBRATE;

关于振动,正如Dan Thomas提到的那样,你需要获得许可(<uses-permission android:name=“android.permission.VIBRATE”/>

为了让劳工局工作,你需要告诉它需要做些什么。

   notification.ledOnMS = 1000; //Be on for a second
   notification.ledOffMS = 1000; //Be off for a second
   notification.ledARGB = Color.GREEN; //What colour should the LED be?

为使工作富有活力,你需要获得你的许可。

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

您是否确保该装置不会被 mu弄,而且用户实际上已经收到一份通知(也没有保持沉默)?

另一项尝试是:

[Note obj].sound = value
[Note obj].LEDARGB = value
[Note obj].vibrate = value

I find there is a setDefaults method in NotificationCompat.Builder , and it provides you for adjusting notification preferences. Here is an example:

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

NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this);

builder.setSmallIcon(R.drawable.taiwanpic)
            .setWhen(System.currentTimeMillis())
            .setContentTitle("AAAAA")
            .setContentText("BBBBB")
            .setSubText("CCCCC")
            .setContentInfo("DDDDD")
            .setTicker("EEEEE")
            .setDefaults(Notification.DEFAULT_ALL);
int pid = android.os.Process.myPid();

notificationManager.notify(pid, builder.build());

如果你不使用所有缺省值,你也可以尝试<代码>。 DEFAULT_SOUND,DEFAULT_VIBRATE,DEFAULT_LLIS, as You need.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签