我希望它在点击屏幕上显示“' notify'”的按钮后创建pendingIntent
通知。因此,当用户点击通知时,它将拨打021-1234567之类的号码。我该怎么做?
我一直在网上寻求帮助,但我似乎无法找到与此有关的任何内容。
public void notifyPendingIntent(View view) {
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+ 0211234567));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// Build notification
Notification notify = new Notification.Builder(this)
.setContentTitle("Make this call")
.setContentText("New call must be made to 021 123 4567")
.setTicker("New Alert")
.setContentIntent(pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notify.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notify);
}
到目前为止,我有这个,但是当我按下按钮时,没有任何反应。
我尝试了这个,它现在有效。感谢所有试图提供帮助的人。
public void notifyPendingIntent(View view) {
NotificationCompat.Builder myNotification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.my_notification_icon)
.setContentText("Calling 021-12345678")
.setContentTitle("Phone Call Notification");
Intent phoneCall = new Intent(Intent.ACTION_CALL);
phoneCall.setData(Uri.parse("tel:021-12345678"));
PendingIntent phoneCallIntent = PendingIntent.getActivity(this, 0, phoneCall, PendingIntent.FLAG_UPDATE_CURRENT);
myNotification.setContentIntent(phoneCallIntent);
NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, myNotification.build());
}
答案 0 :(得分:4)
brew unlink postgresql
试试这个
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
<uses-permission android:name="android.permission.CALL_PHONE" />