我创建了一个通知,我想在点击它时拨打电话,但我不知道该怎么做,我试图找到答案,但我无法做到。
notification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createNotification(v);
}
});
public void createNotification(View view) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
Notification noti = new Notification.Builder(MainActivity.this)
.setContentTitle("Make a Call")
.setContentText("0390000000")
.setSmallIcon(R.drawable.phone)
.setContentIntent(pIntent).getNotification();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
我也必须这样,但我不知道如何把它们放在一起
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel: 0390000000")));
上面的代码只打开拨号器,但我想直接拨打该号码。
感谢任何帮助。
微米。
答案 0 :(得分:1)
尝试
Intent notificationIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
还在清单文件中添加权限
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
答案 1 :(得分:0)