Firefox os activity简析

来源:互联网 发布:下载淘宝注册 编辑:程序博客网 时间:2024/05/20 07:52

Firefox os activity简析

从android中我们可以看到activity 是android 中展示在用户面前的操作载体,firefox也一样拥有相同类似的功能,接下来让我们看看activity在firefox的意义及用法,在firefox os 手机应用开发时我们需要不同的界面跳转时也一样需要activity进行相互交互,不像安卓那样用java编写activity,firefox os 主要用html做指引javascript做控制,额,扯到一边去了,还是看怎么用吧。


首先和android一样需要在manifest中对activity做声明,android的是manifest.xml而firefox os 则是mabifest.webapp

{
  // Other App Manifest related stuff

  // Activity registration
  "activities": {

    // The name of the activity to handle (here "pick")
    "pick": {
      "href": "./pick.html",
      "disposition": "inline",
      "filters": {
        "type": ["image/*","image/jpeg","image/png"]
      },
      "returnValue": true
    }
  }
}

其次是启动要跳转到的activity 即 Starting an activityvar activity = new MozActivity({
  // Ask for the "pick" activity
  name: "pick",

  // Provide de data required by the filters of the activity
  data: {
    type: "image/jpeg"
  }
});

activity.onsuccess = function() {
  var picture = this.result;
  console.log("A picture has been retrieve");
};

activity.onerror = function() {
  console.log(this.error);
};
最后是你所启动的activity要执行什么样的操作
navigator.mozSetMessageHandler('activity', function(activityRequest) {
  var option = activityRequest.source;

  if (option.name === "pick") {
    // Do something to handle the activity
    ...

    // Send back the result
    if (picture) {
      activityRequest.postResult(picture);
    } else {
      activityRequest.postError("Unable to provide a picture");
    }
  }
});
0 0
原创粉丝点击