[转贴]如何让手机识别自定义的文件类型
来源:互联网 发布:js通过class设置样式 编辑:程序博客网 时间:2024/05/17 06:16
MDL是一个库文件,存在c:/system/recogs 目录下(模拟器上没有这个目录可以到手机上找到),用作S60平台中的文件类型识别,下面代码出自SDK help:
/***********************************************************/
/* */
/* MyRecognizer.mmp */
/* */
/***********************************************************/
TARGET MyRecognizer.MDL
TARGETTYPE MDL
UID 0x10003A19 0x100530
TARGETPATH /system/recogs/
SOURCEPATH ../src
SOURCE MyRecocnizer.cpp
USERINCLUDE ../inc
SYSTEMINCLUDE /epoc32/include
LIBRARY EUSER.LIB
LIBRARY APMIME.LIB
/***********************************************************/
/* */
/* MyRecognizer.h */
/* */
/***********************************************************/
// includes
#include <apmrec.h> // For CApaDataRecognizerType
// Mime type string and the extension
_LIT8( KMyMimeType, "application/vnd.mymime" );
_LIT( KDotMymime,".mym" );
// File header to look for from the data
_LIT8( KMyMimeHeader, "#!MY" );
// TUid of the recognizer
const TUid KUidMyMimeRecognizer( { 0x100530 } );
class CMyRecognizer : public CApaDataRecognizerType
{
public: // from CApaDataRecognizerType
CMyRecognizer();
virtual TUint PreferredBufSize();
virtual TDataType SupportedDataTypeL( TInt aIndex ) const;
private: // from CApaDataRecognizerType
virtual void DoRecognizeL(const TDesC& aName,
const TDesC8& aBuffer );
// New funtions
private:
// Check the file name extension
TBool NameRecognized( const TDesC& aName );
// Look into the data
TBool HeaderRecognized( const TDesC8& aName );
};
// End of file
/***********************************************************/
/* */
/* MyRecognizer.cpp */
/* */
/***********************************************************/
// Includes
#include "MyRecognizer.h"
//
// Constructor
//
MyRecognizer::MyRecognizer()
:CApaDataRecognizerType(
KUidMyMimeRecognizer,
CApaDataRecognizerType::EHigh )
{
iCountDataTypes = 1;
}
//
// Preferred buffer size.
//
TUint MyRecognizer::PreferredBufSize()
{
return 128;
}
//
// For the framework for collecting the supported mime types list.
TDataType MyRecognizer::SupportedDataTypeL( TInt aIndex ) const
{
switch( aIndex )
{
case 0:
default:
return TDataType( KMyMimeType );
break;
}
}
//
// The framework calls this function for recognition
//
void MyRecognizer::DoRecognizeL(
const TDesC& aName,
const TDesC8& aBuffer )
{
TBool nameOk( EFalse );
TBool headerOk( EFalse );
iConfidence = ENotRecognized;
if ( aBuffer.Length() < 10 )
return;
// First try the name, then the data.
nameOk = NameRecognized( aName );
headerOk = HeaderRecognized( aBuffer );
if ( nameOk && headerOk )
{
iConfidence = ECertain;
}
else if ( !nameOk && headerOk )
{
iConfidence = EProbable;
}
else if ( nameOk && !headerOk )
{
iConfidence = EPossible;
}
else return;
iDataType = TDataType( KMyMimeType );
}
//
// Check if the file header can be recognized
//
TBool MyRecognizer::HeaderRecognized( const TDesC8& aBuffer )
{
if ( aBuffer.Find( KMyMimeHeader ) )
return ETrue;
else
return EFalse;
}
//
// Check if the file name has ".mym" extension
//
TBool MyRecognizer::NameRecognized( const TDesC& aName )
{
TBool ret = EFalse;
if ( aName.Length() > 5 )
{
TInt dotPos = aName.LocateReverse( '.' );
if (dotPos != KErrNotFound)
{
TInt extLength = aName.Length() - dotPos;
HBufC* ext = aName.Right( extLength ).AllocL();
CleanupStack::PushL( ext );
if ( ext->CompareF( KMyMimeHeader ) == 0 )
{
ret = ETrue;
}
CleanupStack::PopAndDestroy(); // ext
}
}
return ret;
}
//
// The gate function - ordinal 1
EXPORT_C CApaDataRecognizerType* CreateRecognizer()
{
CApaDataRecognizerType* thing = new MyRecognizer();
return thing; // NULL if new failed
}
//
// DLL entry point
//
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return KErrNone;
}
// End of file
- [转贴]如何让手机识别自定义的文件类型
- 如何为file增加文件类型的识别
- windows和linux是如何识别文件类型的?
- linux下如何识别ntfs文件类型的硬盘
- [自定义jsp文件后缀名]如何让Eclipse识别非标准扩展名的文件
- ASP.NET : 如何为网站添加自定义的文件类型
- 如何让VC IDE识别自定义C++ 关键字
- 如何让VC IDE识别自定义C++关键字
- 如何让虚拟机识别插入的优盘
- 文件类型识别
- 如何让手机里的“隐私”“天衣无缝”
- 如何让遗失的手机失而复得
- 如何让X5发现你的手机
- 让MyEclipse的xdoclet 识别自定义的标签属性
- vim、gvim添加不识别的文件类型
- vim、gvim添加不识别的文件类型
- interlliJ idea 不识别文件类型的解决方案
- vim添加未识别文件类型的解决方法
- NestableException和NestableRuntimeException的区别
- 企业网站大气怎么设计!(转)
- (转)图片加水印(类)
- SharePoint初探-SharePoint网站整理
- 政府领域解决方案
- [转贴]如何让手机识别自定义的文件类型
- 加强主机和应用监控 构筑行业高效网管模式——华能巢湖发电有限责任公司
- 怎样对Illustrator制作的SVG进行优化
- 图片加水印
- eclipse实用插件【转帖】
- Mocha BSM业务服务管理——业务服务仪表盘
- 各种比例尺标准分幅图经差、纬差表
- 要培养适应环境变化的创新能力
- 中小企业管理解决方案