1
在我TiApp.xml我得到了以下塊:Titanium android,接收意圖,如何訪問本機文件?
<activity android:name=".TestActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="@string/kmob.intent.menu.send">
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
</intent-filter>
</activity>
,它的工作太棒了。我可以進入照片庫,選擇一張照片,我可以與我的應用程序分享照片。但在我的應用程序中,我遇到了問題。我需要訪問文件名或至少是其擴展名。但是我只有圖像內容的一個blob。
if (OS_ANDROID) {
var intent = Ti.Android.currentActivity.getIntent();
if (intent && intent.action == 'android.intent.action.SEND') {
// Blob contains the content of the image (an application/octet-stream data). But there's no filename or filepath or file mimetype or whatever
var blob = intent.getBlobExtra(Ti.Android.EXTRA_STREAM);
// How can i access the native file or its filename ?
}
}
如何訪問本機文件或其文件名?或者至少是它的擴展? (這是我需要的唯一東西,因爲我有文件內容,我可以創建一個臨時文件,內容由我需要的擴展名)
在文檔中,我只能找到簡單的文本文件的例子或只顯示圖像內容。他們永遠不會訪問本機文件或其文件名。
這裏意圖和Blob的字符串表示:
intent = {
"action": "android.intent.action.SEND",
"bubbleParent": true,
"data": null,
"type": "image/jpeg", // NOTE : This value is not always the same. For an android 4.2.x, it's "image/jpeg", on android 4.1.x, it's "image/*".
"apiName": "Ti.Android.Intent",
"flags": 50331649
};
blob = {
"height": 0,
"bubbleParent": true,
"type": 2,
"mimeType": "application/octet-stream",
"apiName": "Ti.Blob",
"nativePath": null,
"file": null,
"text": "<IMAGE CONTENT AS STRING>"
}
已經嘗試過,沒有成功:(blob只包含圖像內容,'blob.file'和'blob.nativePath'都是'null',我將用我的blob的字符串表示形式編輯我的問題 – Magus
It似乎你的blob不代表一個文件。根據這個問題:http://stackoverflow.com/questions/13488176/titanium-mobile-photogallery-success-callback-event-property-media-file nativePath和文件是不能由開發人員訪問(至少對iOS來說,也許這也是這裏的問題)。mimeType = application/octet-stream表明blob不知道原始文件具有哪個文件擴展名。 –