diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2012-12-29 03:33:50 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2012-12-29 03:33:50 +0100 |
| commit | 38d2a3465bc4b063292c61ef2ba55c5c8bf4b2d2 (patch) | |
| tree | bc85cf69c82139082771d288f4a34f2f34ae3a3f /src | |
| parent | 3c0f79ccdecb9d18093d157da5b804122843efeb (diff) | |
added support for EXTRA_STREAM content. unfortunately it won't read vcards because of missing READ_CONTACTS permissions (which I don't want to give this app).
Diffstat (limited to 'src')
| -rw-r--r-- | src/eu/deki/paste/MainActivity.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/eu/deki/paste/MainActivity.java b/src/eu/deki/paste/MainActivity.java index effd55c..bc2ffa8 100644 --- a/src/eu/deki/paste/MainActivity.java +++ b/src/eu/deki/paste/MainActivity.java @@ -1,6 +1,8 @@ package eu.deki.paste; import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.os.Bundle; import android.widget.Spinner; import android.widget.EditText; @@ -10,6 +12,12 @@ import android.view.Menu; import android.view.MenuItem; import android.view.MenuInflater; import android.content.Intent; +import android.content.ContentResolver; +import android.net.Uri; +import java.io.InputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.FileNotFoundException; import eu.deki.paste.DekiEuPaste; /* @@ -41,6 +49,32 @@ public class MainActivity extends Activity Intent intent = getIntent(); if(intent.hasExtra(Intent.EXTRA_TEXT)) contentText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); + + if(intent.hasExtra(Intent.EXTRA_STREAM)) + { + try { + Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); + ContentResolver cr = getContentResolver(); + InputStream is = cr.openInputStream(uri); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int n = 0; + while((n = is.read(buffer, 0, 1024)) != -1) + output.write(buffer, 0, n); + output.flush(); + contentText.setText(output.toString()); + } catch(FileNotFoundException ex) { + } catch(IOException ex) { + } catch(SecurityException ex) { + // no permissions to read data (e.g. contacts/vcards) + AlertDialog.Builder builder = new AlertDialog.Builder(this); + String message = String.format(getResources().getString(R.string.noPermissionContent), ex.getLocalizedMessage()); + builder.setMessage(message); + builder.setTitle(R.string.noPermissionTitle); + builder.setPositiveButton("OK", null); + builder.create().show(); + } + } } @Override |
