无法从资产列表按钮打开PDF

时间:2016-04-05 02:57:58

标签: android pdf

我有两个应用程序,我在资产文件夹中有PDF。在应用程序A中,代码工作得非常好,但在应用程序B中它无法正常工作。我没有收到任何错误。当点击应用程序B中的按钮时,它会打开adobe acrobat,但是我得到一个祝酒词#34;无法访问此文件。检查位置或网络,然后重试"。我甚至将PDF放在应用程序A中以确保此PDF文件没有任何问题。它在应用程序A中打开很好。

以下是我的应用B代码。我试图通过列表中的按钮打开它。

[CODE]

public class InteractiveArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
static final String TAG = InteractiveArrayAdapter.class.getSimpleName();

String ta = "helen.pdf";
GPXParser mParser = new GPXParser();

public InteractiveArrayAdapter(Context context, String[] values) {
    super(context, R.layout.rowbuttonlayout, values);
    this.context = context;
    this.values = values;
}

static class ViewHolder {
    protected TextView text,header, number, web;
    protected ImageButton web_pic, imageView;
    ImageView bike, atv, utv;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (convertView == null) {
        LayoutInflater inflator = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.rowbuttonlayout, null);
        final ViewHolder viewHolder = new ViewHolder();
        viewHolder.header = (TextView) view.findViewById(R.id.header);
        viewHolder.text = (TextView) view.findViewById(R.id.label);
        viewHolder.bike = (ImageView) view.findViewById(R.id.bike);
        viewHolder.atv = (ImageView) view.findViewById(R.id.atv);
        viewHolder.utv = (ImageView) view.findViewById(R.id.utv);
        viewHolder.web_pic = (ImageButton) view.findViewById(R.id.web_pic);
        viewHolder.imageView = (ImageButton) view.findViewById(R.id.check);
        view.setTag(viewHolder);
        viewHolder.imageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {         

                    Intent myIntent = new Intent(context, MapActivity.class);

                    context.startActivity(myIntent);
                }
            }); 
        viewHolder.web_pic.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    copyReadAssets();

                }       
            });
    }


    ViewHolder holder = (ViewHolder) view.getTag();
    holder.header.setText(values[position]);
    holder.imageView.setImageResource(R.drawable.map1);
    holder.web_pic.setImageResource(R.drawable.pdf);
    holder.bike.setImageResource(R.drawable.bike);
    holder.atv.setImageResource(R.drawable.atv_2);
    holder.utv.setImageResource(R.drawable.utv);

    if (position == 0) {
        holder.text.setText("17.82 mi");



    }
    if (position == 1) {


        holder.text.setText("29.09 mi");

    }
    if (position == 2) {


        holder.text.setText("11.06 mi");

    }


    return view;
}
private void copyReadAssets() {

    AssetManager assetManager =context. getAssets();

    InputStream in = null;
    OutputStream out = null;
    File file = new File(context.getFilesDir(), ta);
    try {
        in = assetManager.open(ta);
        out = context.openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    } catch (Exception e) {
        Log.e("tag", e.getMessage());
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(
        Uri.parse("file://" +context. getFilesDir() + "/"+ta),
        "application/pdf");

   context. startActivity(intent);
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
    }
}

} [CODE /

1 个答案:

答案 0 :(得分:0)

尝试以下代码打开PDF,

python split.py < input.txt