some sharing work

This commit is contained in:
Brad Fitzpatrick 2010-07-19 16:40:04 -07:00
parent 3706901863
commit 542216b0f6
1 changed files with 64 additions and 2 deletions

View File

@ -1,8 +1,17 @@
package com.danga.camli;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -47,13 +56,66 @@ public class CamliActivity extends Activity {
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Intent intent = getIntent();
String action = intent.getAction();
Log.d(TAG, "onResume; action=" + action);
if (Intent.ACTION_SEND.equals(action)) {
handleSend(intent);
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
handleSendMultiple(intent);
}
}
private void handleSendMultiple(Intent intent) {
// TODO Auto-generated method stub
}
private void handleSend(Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null) {
Log.w(TAG, "expected extras in handleSend");
return;
}
extras.keySet(); // unparcel
Log.d(TAG, "handleSend; extras=" + extras);
Object streamValue = extras.get("android.intent.extra.STREAM");
if (!(streamValue instanceof Uri)) {
Log.w(TAG, "Expected URI for STREAM; got: " + streamValue);
return;
}
Uri uri = (Uri) streamValue;
startDownloadOfUri(uri);
}
private void startDownloadOfUri(Uri uri) {
Log.d(TAG, "startDownloadOf: " + uri);
ContentResolver cr = getContentResolver();
ParcelFileDescriptor pfd = null;
try {
pfd = cr.openFileDescriptor(uri, "r");
} catch (FileNotFoundException e) {
Log.w(TAG, "FileNotFound for " + uri, e);
return;
}
Log.d(TAG, "opened parcel fd = " + pfd);
FileDescriptor fd = pfd.getFileDescriptor();
FileInputStream fis = new FileInputStream(fd);
try {
pfd.close();
} catch (IOException e) {
Log.w(TAG, "error closing fd", e);
}
}
}