Android插件

来源:互联网 发布:v380监控软件官网 编辑:程序博客网 时间:2024/05/29 10:43

转自http://www.bangchui.org/read.php?tid=8858

 

插件开发第一课是学习源码中android2.2-froyo/development/samples/BrowserPlugin。这个例子告诉我们,插件开发其实就是写一个apk,使用就是安装一个apk这么简单。
1. 编译,make SampleBrowserPlugin。这个过程中会生成libsampleplugin.so和SampleBrowserPlugin.apk。编译后,动态库已经编译进入apk。
2. 安装时只需要adb install d:/SampleBrowserPlugin.apk
3. 制作test.html
<html>
<body>
<object type="application/x-testbrowserplugin" height=50 width=250>
<param name="DrawingModel" value="Surface" />
<param name="PluginType" value="Background" />
</body>
</html>
把上面的内容保存成test.html。并push到sdcard里
adb push d:/test.html /sdcard/
4. 测试
打开浏览器输入
content://com.android.htmlfileprovider/sdcard/test.html
请参考帖子http://www.bangchui.org/read.php?tid=8857
就可以看到效果了,点点看有什么变化

 

看了Android浏览器插件(plugin)开发入门(一)肯定会有一个疑问,
什么疑问?
测试用的test.html是自己写的,实际使用过程中不可能都看自己的网页吧。
这样的话写个插件只能给自己用,不是笑话了。
其实这个例子test.html里有一个字段
type="application/x-testbrowserplugin"非常关键
我们可以修改这个type,就会发现不能运行,弹出一个蓝色立方体,这是webkit没有找到插件的提示。

这是因为webkit就是根据这个type(完整叫mime-type)插件来找到并启动相应的插件的,所以不能修改。
在android2.2-froyo/development/samples/BrowserPlugin/jni/main.cpp有这样一个函数
const char *NP_GetMIMEDescription(void)
{
    return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin";
}

这个返回有格式要求,不是可以随便写的。
可以包含多个描述,每个MIME type描述必须以;隔开。
而每一个描述要包括3部分:MIME Type, an extensions list and a short description.

看一个函数,看人家怎么写的就明白了
//--------------------------------------------------------------
char *NP_GetMIMEDescription(void) {

xprintf("NPP_GetMIMEDescription:/n");

return "video/mpeg: mpeg, mpg, mpe: MPEG animation;"
        "video/x-mpeg: mpeg, mpg, mpe: MPEG animation;"
        "audio/mpeg2: mp2: MPEG audio;"
        "audio/x-mpeg2: mp2: MPEG audio;"
        "audio/mpeg3: mp3: MPEG audio;"
        "audio/x-mpeg3: mp3: MPEG audio;"
        "audio/mpeg: mpa,abs,mpega: MPEG audio;"
        "audio/x-mpeg: mpa,abs,mpega: MPEG audio;"
        "video/quicktime: mov,qt: Quicktime animation;"
        "video/x-quicktime: mov,qt: Quicktime animation;"
        "video/msvideo: avi: AVI animation;"
        "video/x-msvideo: avi: AVI animation;"
        "application/x-mplayer2: asf,asx,asp: mplayer2;"
        "video/x-ms-asf-plugin: asf,asx,asp: mms animation;"
        /*"audio/x-pn-realaudio-plugin: rpm: Real audio;"*/
        "audio/x-ogg: ogg,ogm: OGG Media;"
        "audio/x-scpls: pls: MPEG audio"
;
}

原创粉丝点击