2015-12-18 81 views
0

是否可以从通知中启动另一个应用程序?例如用于拨打电话的本机应用程序。我的代码是followng,但无法启动调用应用程序。从通知中打开其他应用程序

NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
        .setSmallIcon(R.drawable.ic_call_white_24dp) 
        .setContentTitle("My notification") 
        .setContentText("Hello World!"); 

    Intent myIntent = new Intent(Intent.ACTION_CALL); 
    myIntent.setData(Uri.parse("694154257"));  

    PendingIntent resultPendingIntent = 
      PendingIntent.getActivity(
        this, 
        0, 
        myIntent, 
        PendingIntent.FLAG_UPDATE_CURRENT 
      ); 

    mBuilder.setContentIntent(resultPendingIntent).addAction(R.drawable.ic_call_white_24dp, "Make phone call", resultPendingIntent); 
    NotificationManager mNotificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    // mId allows you to update the notification later on. 
    mNotificationManager.notify(0, mBuilder.build()); 

回答

1

你为什么不使用:

Intent myIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:694154257")); 

顺便说一句,避免使用通知的ID,不到1

mNotificationManager.notify(12, mBuilder.build()); 

欲了解更多信息:

Sending the User to Another App

相关问题