守望者--AIR技术交流

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: ANE FlasCC 炼金术
查看: 475|回复: 0

BaseMobileTasks-ane

[复制链接]
  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    51691
    钢镚
    1422

    开源英雄守望者

    发表于 2015-4-8 16:02:53 | 显示全部楼层 |阅读模式
    应用下载
    应用名称: BaseMobileTasks-ane
    支持64位: 支持
    当前版本: 1.0.0
    运行平台: Android 
    开发语言: ActionScript 3 JAVA 
    应用类别: ANE-JAVA
    应用简介: 获取OS版本字符串
    显示文本显示(Android Toast)
    设置全屏(Android Immersive mode)
    分享图像(用户选择安装的应用程序(如Facebook或Twitter)与共享图片)
    振动设备
    本帖最后由 破晓 于 2015-4-8 17:05 编辑

    获取OS版本字符串
    显示文本显示(Android Toast)
    设置全屏(Android Immersive mode)
    分享图像(用户选择安装的应用程序(如Facebook或Twitter)与共享图片)
    振动设备


    Air Native Extension for Performing Base Tasks on Mobile Devices

    This is an (Android only atm) ane for performing base tasks on device.


    Supported Tasks
    • Get OS Version String
    • Show Text Display (Android Toast)
    • Set Full Screen (Android Immersive mode)
    • Share Image (User selects an installed app (e.g. Facebook or Twitter) to share image with)
    • Device Vibration

    Build

    Compiled .swc and .ane files are included in the bin directory, but to perform a clean build; set the properties in build.properties.template appropriately, change its name to build.properties and run the default ant target in build.xml in the root directory.


    Usage

    The BaseMobileTasks Actionscript class is a Singleton instance and should be accessed withBaseMobileTasks.instance. Before doing so it is recommended to first check if it is supported on the current platform with the static method BaseMobileTasks.isSupported().

    To get the OS Version:

    1. <font color="rgb(51, 51, 51)">if (BaseMobileTasks.isSupported())
    2.     // version = e.g. '5.0.1' - may also be null, so should check before using
    3.     var osVersion:String = BaseMobileTasks.instance.getOSVersion();</font>
    复制代码
    To display a text message (Toast text):

    1. <font color="rgb(51, 51, 51)">if (BaseMobileTasks.isSupported())
    2.     // May also use BaseMobileTasks.TEXT_DISPLAY_SHORT
    3.     BaseMobileTasks.instance.showTextDisplay("Hello World", BaseMobileTasks.TEXT_DISPLAY_LONG);</font>
    复制代码
    To go into full screen (note: requires Android 4.4 or higher):

    1. <font color="rgb(51, 51, 51)">if (BaseMobileTasks.isSupported())
    2. {
    3.     var actualScreenDimensions:Array = BaseMobileTasks.instance.setFullscreen();
    4.     if (actualScreenDimensions != null)
    5.     {
    6.         var actualWidth:int = actualScreenDimensions[0];
    7.         var actualHeight:int = actualScreenDimensions[1];
    8.     }
    9.     else
    10.     {
    11.         // Either an error has occurred or user is on an Android device less than 4.4. You could check with getOSVersion() 1st if desired.
    12.         // Store screen width and height another way (e.g. stage.fullScreenWidth && stage.fullScreenHeight)
    13.     }
    14. }</font>
    复制代码
    To share an image, first save the image to a public directory (I recommend creating an appropriately named folder within File.userDirectory) on the device then send its path to the ane like so:

    1. <font color="rgb(51, 51, 51)">private function ShareImage(image:BitmapData)
    2. {
    3.     // can't share
    4.     if (!BaseMobileTasks.isSupported())
    5.         return;

    6.     var file:File = File.userDirectory.resolvePath("MyApp" + File.separator + "imageName.jpg");

    7.     var imageBytes:ByteArray = image.encode(image.rect, new JPEGEncoderOptions(80));
    8.     var stream:FileStream = new FileStream();
    9.     stream.open(file, FileMode.WRITE);
    10.     stream.writeBytes(imageBytes);
    11.     stream.close();

    12.     BaseMobileTasks.instance.addEventListener(BaseMobileTaskEvent.IMAGE_SHARED, onImageShared);
    13.     BaseMobileTasks.instance.addEventListener(BaseMobileTaskEvent.SHARE_IMAGE_ERROR, onImageShareErr);

    14.     var title:String = "Share Image from MyApp!";
    15.     BaseMobileTasks.instance.shareImage(file.nativePath, title);
    16. }

    17. private function onImageShared(e:BaseMobileTaskEvent):void
    18. {
    19.     // important to remove event listeners from Singleton instance
    20.     BaseMobileTasks.instance.removeEventListener(BaseMobileTaskEvent.IMAGE_SHARED, onImageShared);
    21.     BaseMobileTasks.instance.removeEventListener(BaseMobileTaskEvent.SHARE_IMAGE_ERROR, onImageShareErr);

    22.     // User has been presented with a list of apps to share with. He or she may still decide not to share.
    23. }

    24. private function onImageShareErr(e:BaseMobileTaskEvent):void
    25. {
    26.     // important to remove event listeners from Singleton instance
    27.     BaseMobileTasks.instance.removeEventListener(BaseMobileTaskEvent.IMAGE_SHARED, onImageShared);
    28.     BaseMobileTasks.instance.removeEventListener(BaseMobileTaskEvent.SHARE_IMAGE_ERROR, onImageShareErr);

    29.     trace("Could not share image: " + e.reason);
    30. }</font>
    复制代码
    To vibrate device:

    1. <font color="rgb(51, 51, 51)">if (BaseMobileTasks.isSupported())
    2.     // If vibration is supported on device, device will vibrate for 250 milliseconds
    3.     BaseMobileTasks.instance.vibrate(250);</font>
    复制代码


    Installation


    Include the .swc file in your project and, when compiling, be sure the .ane file is inside your extdir. For more info, RTFM.In your app descriptor include the extension id like:

    1. <font color="rgb(51, 51, 51)"><extensions>
    2.     <extensionID>com.onebyonedesign.basemobiletasks</extensionID>
    3. </extensions></font>
    复制代码
    If planning to share images, be sure to include the Android permission to write to external storage:
    1. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    复制代码
    If planning to vibrate device, be sure to include the Android permission to do so:
    1. <uses-permission android:name="android.permission.VIBRATE"/>
    复制代码
    Notes
    • The .swc and .ane files included in the bin directory were compiled using AIR 16.0 sdk and swf-version 27 (16.0)3








    相关链接:

    https://github.com/devon-o/BaseMobileTasks-ane

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    守望者AIR技术交流社区(www.airmyth.com)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    
    关闭

    站长推荐上一条 /4 下一条

    QQ|手机版|Archiver|网站地图|小黑屋|守望者 ( 京ICP备14061876号

    GMT+8, 2019-8-20 22:27 , Processed in 0.040265 second(s), 34 queries .

    守望者AIR

    守望者AIR技术交流社区

    本站成立于 2014年12月31日

    快速回复 返回顶部 返回列表