Android Open Source - smartcard-reader File Share Activity






From Project

Back to project page smartcard-reader.

License

The source code is released under:

GNU General Public License

If you think the Android project smartcard-reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.docrj.smartcard.reader;
// w  ww  . j  av  a2  s  .  c  o  m
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.content.Intent;
import android.view.Gravity;
import android.widget.Toast;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;

public class FileShareActivity extends Activity {
    private static final String TAG = "smartcard-reader";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Intent intent = getIntent();
        Spanned text = (Spanned) intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
        if (text != null &&
            Intent.ACTION_SEND.equals(intent.getAction()) &&
            "text/html".equals(intent.getType())) {
            // check external storage
            if (isExternalStorageWritable()) {
                // write string to file
                try {
                    File file = new File(getExternalFilesDir(null),
                        "smartcard_reader_" + System.currentTimeMillis() + ".html");
                    Log.d(TAG, "abs file path: " + file.getAbsolutePath());
                    OutputStream os = new FileOutputStream(file);
                    OutputStreamWriter osw = new OutputStreamWriter(os);
                    osw.write(Html.toHtml(text));
                    osw.close();
                    showToast(getString(R.string.saved_to, file.getName()));

                    // add file to media library for viewing via mtp
                    Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    scanIntent.setData(Uri.fromFile(file));
                    sendBroadcast(scanIntent);
                } catch (IOException e) {
                    Log.e(TAG, "failed to write file: " + e.toString());
                    showToast(getString(R.string.save_exception));
                }
            } else {
                showToast(getString(R.string.save_not_mounted));                
            }
        }

        finish();
    }
    
    private boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        return false;
    }

    private void showToast(String text) {
        Toast toast = Toast.makeText(FileShareActivity.this, text,
                Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, -100);
        toast.show();
    }

    /*
    private boolean hasSavedFiles() {
        File dir = getExternalFilesDir(null);
        File[] files = dir.listFiles();
        return files.length > 0;
    }

    private void deleteSavedFiles() {
        File dir = getExternalFilesDir(null);
        File[] files = dir.listFiles();
        if (files.length > 0) {
            for (File file : dir.listFiles()) {
                file.delete();
            }
            showToast("deleted saved files");
        } else {
            showToast("no saved files");
        }
    }

    private void deleteRecursively(File file) {
        if (file.isDirectory()) {
            for (File child : file.listFiles()) {
                // recursion
                deleteRecursively(child);
            }
        }
        file.delete();
    }
    */
}




Java Source Code List

org.docrj.smartcard.emv.AppElementaryFile.java
org.docrj.smartcard.emv.AppFileLocator.java
org.docrj.smartcard.emv.AppInterchangeProfile.java
org.docrj.smartcard.emv.AppPriorityIndicator.java
org.docrj.smartcard.emv.DDF.java
org.docrj.smartcard.emv.DOL.java
org.docrj.smartcard.emv.EMVApp.java
org.docrj.smartcard.emv.EMVTags.java
org.docrj.smartcard.emv.EMVTerminal.java
org.docrj.smartcard.emv.GpoApdu.java
org.docrj.smartcard.emv.IssuerIdNumber.java
org.docrj.smartcard.emv.LanguagePref.java
org.docrj.smartcard.emv.LogEntry.java
org.docrj.smartcard.emv.MCTags.java
org.docrj.smartcard.emv.Record.java
org.docrj.smartcard.emv.TagProvider.java
org.docrj.smartcard.emv.TerminalTranQualifiers.java
org.docrj.smartcard.emv.TerminalVerifResults.java
org.docrj.smartcard.emv.VISATags.java
org.docrj.smartcard.iso7816.BERTLV.java
org.docrj.smartcard.iso7816.CommandApdu.java
org.docrj.smartcard.iso7816.ReadRecordApdu.java
org.docrj.smartcard.iso7816.ResponseApdu.java
org.docrj.smartcard.iso7816.SelectApdu.java
org.docrj.smartcard.iso7816.SmartcardException.java
org.docrj.smartcard.iso7816.TLVException.java
org.docrj.smartcard.iso7816.TLVUtil.java
org.docrj.smartcard.iso7816.TagAndLength.java
org.docrj.smartcard.iso7816.TagImpl.java
org.docrj.smartcard.iso7816.TagType.java
org.docrj.smartcard.iso7816.TagValueType.java
org.docrj.smartcard.iso7816.Tag.java
org.docrj.smartcard.reader.ApduParser.java
org.docrj.smartcard.reader.AppAdapter.java
org.docrj.smartcard.reader.DemoReaderXcvr.java
org.docrj.smartcard.reader.FileShareActivity.java
org.docrj.smartcard.reader.ManualReaderXcvr.java
org.docrj.smartcard.reader.MessageAdapter.java
org.docrj.smartcard.reader.OtherReaderXcvr.java
org.docrj.smartcard.reader.PaymentReaderXcvr.java
org.docrj.smartcard.reader.ReaderActivity.java
org.docrj.smartcard.reader.ReaderXcvr.java
org.docrj.smartcard.reader.SmartcardApp.java
org.docrj.smartcard.util.ByteArrayWrapper.java
org.docrj.smartcard.util.ISO3166_1.java
org.docrj.smartcard.util.ISO4217_Numeric.java
org.docrj.smartcard.util.Util.java