如何在安卓系统中调用活动意图?

3
我正在开发一款安卓应用。我可以通过Parse REST API向应用发送推送通知。 但是我需要在REST API中发送操作字段(intent)以打开正确的屏幕。 目前它只能打开主屏幕。
现在它只能打开主屏幕。如何通过Parse REST API指定意图以打开品牌活动类(test.mm.brand)?
我的安卓清单文件如下。
<activity
    android:name=".MofActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name="test.mm.brand" />
<activity android:name="test.mm.CustomizedListView" />
<activity android:name="test.mm.HallofFame" />
<activity android:name="test.mm.VideoList" />

REST请求

curl  -X  POST -H "X-Parse-Application-Id: ntItEUY1LZ949R9zfTWDuZORE6dnjICxOni9L9nU" -H "X-Parse-REST-API-Key: dwYZ2DeKutwtswDgWTYkboIw6hRplwSNDR20GiMt" -H "Content-Type: application/json"  -d '{ "where": { "deviceType": "android" }, "data": { "alert": "Your suitcase has been filled with tiny robots!", "action": "test.mm.brand", "title" : "dddd" } }' https://api.parse.com/1/push

你通过RestAPI发送了哪些信息? - asloob
added it in the question - Vidya
你是如何创建通知的? - asloob
通过相同的REST API请求,我添加了。 - Vidya
@rrmo,嘿,如果你的问题解决了,请给我提供一个演示...这会很有帮助的。 - MGDroid
1个回答

4

您需要创建一个接收器来按照此处提供的方式获取通知 Parse Android Notification - responding to payloads

将以下内容添加到您的清单中

<receiver android:name="test.mm.MyCustomReceiver">
<intent-filter>
  <action android:name="test.mm.brand" />
</intent-filter>
</receiver>

创建这个类。
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";

  @Override
  public void onReceive(Context context, Intent intent) {
    try {
      String action = intent.getAction();
      if(action.equalsIngnoreCase("test.mm.brand") {
        Intent intent = new Intent(context, test.mm.brand.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i); 
      }

    }
  }
}

无法调用startActivity,因为该类未扩展Activity类。感谢您的帮助。 - Vidya
1
如果我们在清单中使用接收器,那么情况就是这样。但是当我们使用PushService.setDefaultPushCallback(...)时,默认会触发一个活动。我如何在此函数中获取REST字段?我之所以问这个问题,是因为当我们使用广播接收器时,它会自动使用后台功能打开正确的屏幕,但是当我们点击通知时,它会打开在解析回调函数中设置的默认屏幕。 - Vidya
@rrmo,我们可以通过推送打开主活动以外的其他活动吗? - MGDroid
我尝试过这个,但对我没有用,有什么建议吗? - Ronak Mehta
我已经在我的自定义广播接收器中获取了所有数据,但是我该如何处理这些数据或者如何使用 getIntent() 获取这些数据,并在哪个类中使用这些数据,以便我可以使用特定的值启动一个活动? - Amit Patel
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接