【问题标题】:How to use PendingIntent on BroadcastReceiver如何在 BroadcastReceiver 上使用 PendingIntent
【发布时间】:2012-09-04 04:28:20
【问题描述】:

我正在尝试设置一个消息应用程序:

  1. 首先我们在 PreferenceConnector 上设置一条消息,然后我们收到 然后发消息
  2. BroadcastReceiver 检查消息内容是否相等
  3. 我想获得一个 PendingIntent。
尝试 { if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) { Intent i=new Intent(context, SecureMobiActivity.class); PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); } 别的 { Toast.makeText(Remotelock.this, "消息不相等!", Toast.LENGTH_LONG).show(); } 捕获(异常 e){ // TODO: 处理异常 e.printStackTrace(); }

【问题讨论】:

  • 缺少右括号。

标签: android-intent ubuntu-11.04 ubuntu-10.10


【解决方案1】:

答案很简单

try {
    if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) {
        Intent i = new Intent(mContext,SecureMobiActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
    } else {
        Toast.makeText(Remotelock.this, "message are not equal!", Toast.LENGTH_LONG).show();
    }
    catch (Exception e) {
    // TODO: handle exception
        e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多