【问题标题】:How do I make a notification that makes a call to a number?如何发出呼叫某个号码的通知?
【发布时间】:2015-11-01 19:34:35
【问题描述】:

我希望它在单击屏幕上显示“通知”的按钮后创建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());

}

【问题讨论】:

    标签: android android-intent notifications android-phone-call


    【解决方案1】:
    <!-- NOTE! Your uses-permission must be outside the "application" tag
               but within the "manifest" tag. -->
    
    <uses-permission android:name="android.permission.CALL_PHONE" />
    

    试试这个

    public void call() {
        Toast.makeText(this,"call",Toast.LENGTH_SHORT).show();
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel: 0211234567"));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(getResources().getString(R.string.app_name))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    
    
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        notificationBuilder.setStyle(inboxStyle);
        inboxStyle.setBigContentTitle("sdjshfjnds");
        inboxStyle.addLine("sdjjsdfn");
        notificationBuilder.setStyle(inboxStyle);
    
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        int NOTIFICATION_ID = 100;
        notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
    }
    

    【讨论】:

    • 如何获得运行时调用的权限?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    相关资源
    最近更新 更多