启动通知,点击它时,运行其他功能

时间:2018-01-06 21:50:29

标签: android android-intent notifications

解决。这个问题由Diego D解决。

此代码通过函数启动通知:通知(final String mytext)。 我们通过自动收报机,标题,文本,自动取消等获得通知......当点击它时,运行其他功能: My_Function(mytext);

要使用,它不需要修改AndroidManifest因为使用广播。

<!-- Lead Modal-->
    <div class="modal fade" id="leadModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header"><?php
          $id = $_GET["id"];
           $query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
            <h5 class="modal-title" id="exampleModalLabel"><?php echo $line['first']; ?>&nbsp;<?php echo $line['last']; ?>'s Existing Lead</h5><?php } ?>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body"><?php

$id = $_GET["id"];
$query = "SELECT * FROM leads WHERE id=$id";
$result = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 

?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr align="center">
    <td>
<table width="750" border="2" align="center" cellpadding="1" cellspacing="0" class="table">

  <tr>    
        <td>Original Agent:</td>
    <td><?php echo $line['agent']; ?></td>
  </tr>
 <?php if ($line['upagent'] == ''){  } else { ?>   <tr>    
        <td>Last Updated By:</td>
    <td><?php echo $line['upagent']; ?></td>
  </tr><?php } ?>
  <tr>
    <td width="186">First Name:</td>
    <td width="552">
      <?php echo $line['first']; ?></td>
  </tr>
<?php if ($line['last'] == ''){  } else { ?>  <tr>
    <td>Last Name:</td>
    <td><?php echo $line['last']; ?></td>
  </tr><?php } ?>
  <?php if ($line['email'] == ''){  } else { ?><tr>
    <td>E-Mail Address:</td>
    <td><?php echo $line['email']; ?></td>
  </tr><?php } ?>
  <tr>
    <td>Primary Phone:</td>
    <td><?php echo $line['PrimePhone1']; echo '-'; echo $line['PrimePhone2']; echo '-'; echo $line['PrimePhone3']; ?></td>
  </tr>
 <?php if ($line['AltPhone1'] == '' || $line['AltPhone2'] == '' || $line['AltPhone3'] == '') {  } else { ?> 
<tr>
    <td>Alternate Phone:</td>
    <td><?php echo $line['AltPhone1']; echo '-'; echo $line['AltPhone2']; echo '-'; echo $line['AltPhone3']; ?></td>
  </tr>
<?php } ?>
  <tr>
    <td>Lead Created:</td>
    <td><?php echo $line['datecreated']; ?></td>
  </tr>
<?php if($line['emailsent'] == 1){  ?> <tr>
    <td>Follow-Up Email Sent:</td>
    <td><?php echo $line['followupsent']; ?></td>
  </tr>
  <?php } ?>
  <tr>
    <td>Arrival Date:</td>
    <td><?php echo $line['arrival']; ?></td>
  </tr>
  <tr>
    <td>Departure Date:</td>
    <td><?php echo $line['departure']; ?></td>
  </tr>
  <?php if ($line['adults'] == ''){  } else { ?>
  <tr>
   <td>Adults:</td>
    <td><?php echo $line['adults']; ?></td>
  </tr><?php } ?>
 <?php if ($line['child'] == ''){  } else { ?>
  <tr>
    <td>Children:</td>
    <td><?php echo $line['child']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['area'] == ''){  } else { ?>
 <tr>
    <td>Requested Area:</td>
    <td><?php echo $line['area']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['budget'] == ''){  } else { ?>
 <tr>
    <td>Budget:</td>
    <td><?php echo $line['budget']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['suggested'] == ''){  } else { ?>
 <tr>
    <td>Suggested Properties:</td>
    <td><?php echo $line['suggested']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['discount'] == ''){  } else { ?> 
<tr>
    <td>Discount Offered:</td>
    <td><?php echo $line['discount']; ?></td>
  </tr>
<?php } ?>
  <?php if ($line['promo'] == ''){  } else { ?> 
<tr>
    <td>Promo Code:</td>
    <td><?php echo $line['promo']; ?></td>
  </tr>
<?php } ?>
  <tr>
    <td>Lead Status:</td>
    <td><?php echo $line['status']; ?></td>
  </tr>
  <?php if ($line['notes'] == ''){  } else { ?>     
<tr>
    <td height="85">Additional Notes:</td>
    <td><?php echo $line['notes']; ?></td>
  </tr>
<?php } ?>
 <?php if ($line['resnum'] == ''){  } else { ?>  
<tr>
    <td>Reservation Number:</td>
    <td><?php echo $line['resnum']; ?></td>
</tr><?php } } ?>


</table>

    </td>
  </tr>
</table>

</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
            <a class="btn btn-primary" href="#">Button</a>
          </div>
        </div>
      </div>
    </div>

1 个答案:

答案 0 :(得分:0)

Intent中的PendingIntent设置自定义操作并向其注册接收器,然后您就可以执行所需操作:

Intent notifIntent = new Intent("action_call_method");
PendingIntent pendingmyIntent = PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);

然后注册BroadcastReceiver

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("action_call_method")) {
                // Call your method here
            }
        }
    };

    IntentFilter filter = new IntentFilter("action_call_method");
    registerReceiver(receiver, filter);

不要忘记取消注册接收者。