Firefox os activity简析
发布日期:2021-09-25 17:30:20 浏览次数:2 分类:技术文章

本文共 1322 字,大约阅读时间需要 4 分钟。

从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");
    }
  }
});

转载地址:https://blog.csdn.net/cui_shuang_xi/article/details/24690993 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:WEB应用的跨域调用
下一篇:js的 new image()

发表评论

最新留言

很好
[***.229.124.182]2024年04月11日 03时02分57秒