从 Adob​​e 导入 PDF

Import PDF from adobe

我希望在 andriod studio 中执行以下操作

  1. 用户将打开他的邮件客户端并单击 PDF 预览。它在 adobe reader 中打开文件。

  2. 用户在 adobe 中发表评论,完成后按分享

  3. 显示了我的 andriod 应用程序,用户选择了我的应用程序

  4. 我的 andriod 应用获取 pdf 并将其保存到我的服务器外部。

到目前为止,我有第 1、2、3 部分,但没有第 4、5 部分。据我了解,您无法访问应用程序存储空间,但是张贴者发布了这个,但我不确定如何使用它?

为了获取 PDF,您需要为此用例创建一个 activity 来侦听那些 "sharing" 意图。

ShareActivity.java

void onCreate (Bundle savedInstanceState) {

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("application/pdf".equals(type)) {
            handlePDF(intent);
        } 
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("application/pdf")) {
           // Handle multiple pdfs being sent
        }
    } else {
        // Handle other intents, such as being started from the home screen
    }
}


void handlePDF(Intent intent) {
    Uri pdfUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (pdfUri != null) {

        // TODO: Use your server-side here to save. 

    }
}

然后将其添加到您的 AndroidManifest.xml,以便 Android 知道 activity 当他们 select 将您的应用程序分享到:

时会得到什么
<activity android:name=".ui.ShareActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="application/pdf" />
    </intent-filter>
</activity>
public class savepdf extends ActionBarActivity {
    static final int REQUEST_IMAGE_OPEN = 1;
    private static final int WRITE_REQUEST_CODE = 43;
    private Uri mData;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_savepdf);

        // Get intent, action and MIME type
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("application/pdf".equals(type)) {
                handlePDF(intent);
            }
        } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
            if (type.startsWith("application/pdf")) {
                // Handle multiple pdfs being sent
            }
        } else {
            // Handle other intents, such as being started from the home screen
        }
    }

    void handlePDF(Intent intent) {
        Uri pdfUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (pdfUri != null) {
            //savefile(pdfUri);

            String sourceFilename= pdfUri.getPath();
            String destinationFilename = android.os.Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"abc.pdf";

            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;

            try {
                bis = new BufferedInputStream(new FileInputStream(sourceFilename));
                bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
                byte[] buf = new byte[1024];
                bis.read(buf);
                do {
                    bos.write(buf);
                } while(bis.read(buf) != -1);
            } catch (IOException e) {

            } finally {
                try {
                    if (bis != null) bis.close();
                    if (bos != null) bos.close();
                } catch (IOException e) {

                }
            }















            // TODO: Use your server-side here to save.

        }







       }