我想打開一個excel文件,當用戶從listview中選擇它。我想知道打開的文件是否被編輯。當用戶編輯一個文件時,我想將該文件上傳到服務器,我該怎麼做。我嘗試了下面的代碼,但「onactivityresult」方法沒有被調用。當我編輯使用ACTION_EDIT意圖的Excel文件時,Android onActivityResult未被調用。
代碼:
清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.m.media"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.EDIT"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- <data android:mimeType="image/*" />
<data android:mimeType="video/*" /> -->
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
</manifest>
MyActivity:
listviewv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item=filenames.get(position);
String ext = item.substring(item.lastIndexOf(".")+1);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(ext);
File videoFile2Play = new File(filepath.get(position));
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_EDIT);
i.setDataAndType(Uri.fromFile(videoFile2Play), type);
i.putExtra("finishActivityOnSaveCompleted", true);
startActivityForResult(i, EDIT_CONTACT_RESULT);
// Toast.makeText(getBaseContext(), filepath.get(position), Toast.LENGTH_LONG).show();
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == EDIT_CONTACT_RESULT) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Toast.makeText(getBaseContext(), "edited", Toast.LENGTH_LONG).show();
}
}
}
但是當我保存編輯更改onactivityresult方法是沒有得到調用。如何在打開的文件中發生編輯時收到通知。請幫我解決這個問題。
我使用android vesion-4.0.3。
「EDIT_CONTACT_RESULT」常數的值是多少? –
你怎麼知道'onActivityResult()'沒有被調用?你只檢查'resultCode == RESULT_OK',然後生成'Toast'(順便說一句,這不是一種可靠的調試方式),但是'resultCode'也可以是'RESULT_CANCELED',特別是如果你的活動啓動正在運行另一項任務。 –
是的,我得到resultCode RESULT_CANCELED。我如何檢測文件是否已被修改。 –