【发布时间】:2017-11-06 02:07:30
【问题描述】:
所以我对 android 还很陌生,我正在尝试让一个按钮创建一个通知,然后单击此通知拨打电话。我在网上做了很多环顾四周,但我仍然无法弄清楚为什么这不起作用。我有这个方法。
public void notification(){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel: 0210000001"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
android.support.v4.app.NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("My notification")
.setContentText("Click to ring 021 000 0001")
.setContentIntent(pendingIntent);
}
以及调用该方法的这个按钮。
Button notif = (Button) findViewById(R.id.notificationButton);
notif.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notification();
}
});}
任何帮助将不胜感激。
【问题讨论】:
标签: android android-intent notifications