gpt4 book ai didi

android - 如何使用通知 addAction 调用方法或电话号码

转载 作者:行者123 更新时间:2023-11-30 02:34:52 28 4
gpt4 key购买 nike

我正在尝试调用此方法` 或者更重要的是在我按下 addAction 按钮时调用一个数字。

public void call(){
Log.i(TAG,"Attempting Call "+emergecyNumber);
Intent callIntent = new Intent(Intent.ACTION_CALL);
//callIntent.setData(Uri.parse("tel:" +emergecyNumber));
startActivity(callIntent);
}`

我的通知

public void startFallNotification(String name, String loc){

    Intent intent = new Intent(); //create intent for notifcation
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);


Notification noti = new Notification.Builder(this)
.setVibrate(new long[]{1000,1000,1000,1000,1000}) //sets vibrate
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
//sets sound
.setTicker(name+" has fallen at "+loc)
.setContentTitle(name+" has fallen at "+loc)
.setContentText(n+" has fallen")
.setSmallIcon(R.drawable.ic_launcher)
.addAction(R.drawable.ic_launcher, "Call Now", null)
.setContentIntent(pIntent).getNotification();

NotificationManager notiMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notiMan.notify(0,noti);
}

最佳答案

您需要使用 CALL 操作创建一个 PendingIntent,并在您在 Notification 上调用 addAction() 时提供它。像这样:

// This activity will be started when the user clicks on the notification
Intent intent = new Intent(); //create intent for notifcation
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

// Create a PendingIntent for the CALL action
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" +emergecyNumber));
PendingIntent callPendingIntent = PendingIntent.getActivity(this, 0, callIntent, 0);


Notification noti = new Notification.Builder(this)
.setVibrate(new long[]{1000,1000,1000,1000,1000}) //sets vibrate
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
//sets sound
.setTicker(name+" has fallen at "+loc)
.setContentTitle(name+" has fallen at "+loc)
.setContentText(n+" has fallen")
.setSmallIcon(R.drawable.ic_launcher)
.addAction(R.drawable.ic_launcher, "Call Now", callPendingIntent)
.setContentIntent(pIntent).getNotification();

关于android - 如何使用通知 addAction 调用方法或电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26730494/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com