我想在andriod工作室做以下工作
用户将打开他的邮件客户端,然后单击PDF上的预览。它将在Adobe Reader中打开文件。
用户在Adobe中发表评论,完成后按分享
显示了我的Andriod应用,用户选择了我的应用
我的Andriod应用程序获取pdf并将其保存到我的服务器的外部。
到目前为止,我有第1,2,3部分,但没有第4,5部分。我的理解是您无法访问应用程序存储,但是张贴者张贴了此消息,但是我不确定如何使用它?
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.
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句