我有以下代码从远程查看器中提取pdf文档以查看:
package com.example.techvault;
import java.io.File;
import java.io.IOException;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
public class PDFFromServerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document);
Intent in= getIntent(); // gets the previously created intent
String url = in.getStringExtra("full_url");
if (!url.startsWith("http://") && !url.startsWith("https://")){
url = "http://ezdrawdocs.com" + url;
}
Log.d("pdf url: ",url);
String extStorageDirectory = Environment.getExternalStorageDirectory()
.toString();
File folder = new File(extStorageDirectory, "pdf");
folder.mkdir();
File file = new File(folder, "Read.pdf");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
Downloader.DownloadFile(url, file);
showPdf();
}
public void showPdf()
{
File file = new File(Environment.getExternalStorageDirectory()+"/pdf/Read.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
}
}
选择后退箭头后,它会重定向到空白屏幕。如何选择重定向时控制重定向到哪个活动? 感谢
答案 0 :(得分:0)
您可以使用
在活动中的清单中定义<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.yourapp.SomeActivity" />
答案 1 :(得分:0)
你在这里做的是实现我称之为“直通活动”(没有用户界面并立即启动不同活动的活动)......我个人试图避免它们。
也就是说,您需要做的是在Activity.finish()
showPDF()
之后致电Activity.onCreate()
。这将关闭你的直通,这样当你退出PDF查看器时,你将不会回到直通。