我没有找到这个问题的答案。 我有一个VOIP应用程序。我可以在本机呼叫日志中添加有关未接来电的日志,但不会显示通知。 有没有办法让设备本机通话记录显示通知? 我不想添加自己的通知,因为我想确保图标始终是本机调用日志应用程序为其他调用显示的图标。
我找到了this,但没有答案。 我使用的代码类似于上一篇文章中显示的代码。
答案 0 :(得分:2)
为了清楚起见:
您仍然可以添加自己的通知,但使用Android系统内置图标 - 这些图标与内置电话应用正在使用的图标相同。例如:
Notification notification = new Notification();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.icon = android.R.drawable.stat_notify_missed_call;
这样,您将始终显示特定Android操作系统版本的特征图标。
有关详细信息,请查看Icon Guidelines,尤其是您的情况 - the status bar icons。
答案 1 :(得分:1)
如果您只是在通话记录db中添加一个条目,则不会显示notificatin。 您需要添加通知。 如果您没有添加自己的通知,只有在电话启动时才会显示通知,如果通话记录仍在那里。
答案 2 :(得分:0)
这是我的实现(主要是从android代码中复制而来):
private static void showMissedCallNotification(Context context, final Contact contact) {
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// display the first line of the notification:
// 1 missed call: call name
// more than 1 missed call: <number of calls> + "missed calls"
int titleResId;
String expandedText;
numberMissedCalls++;
if (numberMissedCalls == 1) {
titleResId = R.string.notification_missedCallTitle;
expandedText = contact.getDisplayName();
} else {
titleResId = R.string.notification_missedCallsTitle;
expandedText = context.getString(R.string.notification_missedCallsMsg,
numberMissedCalls);
}
final PendingIntent callLogIntent = createCallLogIntent(context);
// make the notification
int id = android.R.drawable.stat_notify_missed_call;
String ticker = context.getString(R.string.notification_missedCallTicker, contact.getDisplayNumber());
long currentTime = Platform.timeProvider().getTime();
Notification note = new Notification(id, ticker, currentTime);
note.setLatestEventInfo(context, context.getText(titleResId), expandedText, callLogIntent);
note.flags |= Notification.FLAG_AUTO_CANCEL;
// This intent will be called when the notification is dismissed.
// It will take care of clearing the list of missed calls.
note.deleteIntent = createClearMissedCallsIntent(context);
//configureLedNotification(note);
notificationManager.notify(MISSED_CALL_NOTIFICATION, note);
}
/**
* Returns an intent to be invoked when the missed call notification is clicked.
* @param context
*/
private static PendingIntent createCallLogIntent(Context context) {
Intent intent = new Intent(context, ClearMissedCallsService.class);
intent.setAction(ClearMissedCallsService.ACTION_OPEN_CALL_LOGS);
return PendingIntent.getService(context, 0, intent, 0);
}
/**
* Returns an intent to be invoked when the missed call notification is cleared.
* @param context
*/
private static PendingIntent createClearMissedCallsIntent(Context context) {
Intent intent = new Intent(context, ClearMissedCallsService.class);
intent.setAction(ClearMissedCallsService.ACTION_CLEAR_MISSED_CALLS);
return PendingIntent.getService(context, 0, intent, 0);
}
/*package */ static void cancelMissedCallNotification() {
// reset the number of missed calls to 0.
numberMissedCalls = 0;
notificationManager.cancel(MISSED_CALL_NOTIFICATION);
}
和
/**
* Handles the intent to clear the missed calls that is triggered when a notification is dismissed.
*/
public class ClearMissedCallsService extends IntentService {
/** This action is used to clear missed calls. */
public static final String ACTION_CLEAR_MISSED_CALLS = "com.android.phone.intent.CLEAR_MISSED_CALLS";
public static final String ACTION_OPEN_CALL_LOGS = "com.android.phone.intent.OPEN_CALL_LOGS";
public ClearMissedCallsService() {
super(ClearMissedCallsService.class.getSimpleName());
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
protected void onHandleIntent(Intent intent) {
// Clear the list of new missed calls.
ContentValues values = new ContentValues();
values.put(Calls.NEW, 0);
StringBuilder where = new StringBuilder();
where.append(Calls.NEW);
where.append(" = 1 AND ");
where.append(Calls.TYPE);
where.append(" = ?");
getContentResolver().update(Calls.CONTENT_URI, values, where.toString(),
new String[]{ Integer.toString(Calls.MISSED_TYPE) });
NativeCallLog.cancelMissedCallNotification();
if (ACTION_OPEN_CALL_LOGS.equals(intent.getAction())) {
Intent intentOpenCallLogs = createOpenCallLogIntent();
startActivity(intentOpenCallLogs);
}
}
private static Intent createOpenCallLogIntent() {
Intent intent = new Intent(Intent.ACTION_VIEW, null);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.dir/calls");
return intent;
}
}
您还需要在AndroidManifest中添加它
<service android:exported="true" android:name="yourpackage.ClearMissedCallsService" > <intent-filter > <action android:name="com.android.phone.intent.CLEAR_MISSED_CALLS" /> </intent-filter> <intent-filter > <action android:name="com.android.phone.intent.OPEN_CALL_LOGS" /> </intent-filter> </service>