From 38d2a3465bc4b063292c61ef2ba55c5c8bf4b2d2 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sat, 29 Dec 2012 03:33:50 +0100 Subject: 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). --- res/values-de/strings.xml | 2 ++ res/values/strings.xml | 2 ++ src/eu/deki/paste/MainActivity.java | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 434ed42..5601d0b 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -10,4 +10,6 @@ Dein Text konnte nicht abgeschickt werden.\nGrund:\n%1$s Inhalt ist zu kurz. Text löschen + Keine Berechtigung + Die Anwendung hat keine Zugriffsrechte auf die gesendeten Daten.\n\n%1$s diff --git a/res/values/strings.xml b/res/values/strings.xml index 5a5fa01..c3e3acd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10,4 +10,6 @@ Your paste could not be submitted.\nReason:\n%1$s Content is too short. Clear text + Permission denied + App has no permission to access sent data.\n\n%1$s 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 -- cgit v1.2.3