按钮的onclick查看PDF文件的Andr​​oid [英] Button onclick view pdf file Android

查看:168
本文介绍了按钮的onclick查看PDF文件的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想code Android Studio中一个按钮,将推出PDF文件。我做了一个新的å文件下的资源文件夹,我希望该按钮将调用该PDF文件。然而,它不断想出PDF没有发现?是不是有什么毛病我code?

 按钮BTN =(按钮)findViewById(R.id.button1);        btn.setOnClickListener(新View.OnClickListener()
        {
          公共无效的onClick(视图v){
           档案文件=新的文件(@ Eng_Curr / Eng_Curr.pdf);
           意向意图=新意图(Intent.ACTION_VIEW);
           intent.setDataAndType(Uri.fromFile(文件),@ Eng_Curr / Eng_Curr.pdf);
           intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
           startActivity(意向);
            }
        });


解决方案

嗨伙计所以服用所有的忠告是多少AP preciated我已经找到了工作,围绕此之后。我用了一个刷卡功能,PNG图片和mViewFlipper与SwipeGestureDetector沿之间刷卡。然而与此的问题之一是存储器不足。我是pretty肯定是下到PNG文件的大小,但我可能还需要找到一种方法,每次刷卡之后终止保存的实例。还在研究它,任何建议将是有益的。无论如何希望这code有助于。

 公共类英语延伸活动{    公共类英语延伸活动{
    私有静态最终诠释SWIPE_MIN_DISTANCE = 520;
    私有静态最终诠释SWIPE_THRESHOLD_VELOCITY = 500;
    私人ViewFlipper mViewFlipper;
    私人语境mContext; 私人最终GestureDetector探测器=新GestureDetector(新SwipeGestureDetector());    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.infant_eng);
        mContext =这一点;
        mViewFlipper =(ViewFlipper)this.findViewById(R.id.view_flipper);
        mViewFlipper.setOnTouchListener(新View.OnTouchListener(){
            @覆盖
            公共布尔onTouch(最终查看视图,最终MotionEvent事件){
                detector.onTouchEvent(事件);
                返回true;
            }
        });
    }    类SwipeGestureDetector扩展GestureDetector.SimpleOnGestureListener {        公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){
            尝试{
                //从右向左轻扫
                如果(e1.getX() - e2.getX()> SWIPE_MIN_DISTANCE&放大器;&放大器; Math.abs(velocityX)GT; SWIPE_THRESHOLD_VELOCITY){
                    mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext,R.anim.left_in));
                    mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.left_out));
                    mViewFlipper.showNext();
                    返回true;
                }否则如果(e2.getX() - e1.getX()> SWIPE_MIN_DISTANCE&放大器;&放大器; Math.abs(velocityX)GT; SWIPE_THRESHOLD_VELOCITY){
                    mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext,R.anim.right_in));
                    mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.right_out));
                    mViewFlipper.show previous();
                    返回true;
                }            }赶上(例外五){
                e.printStackTrace();
            }            返回false;
        }
    }
}

Hi I am trying to code a button in Android Studio that will launch a pdf file. I have made a new afile under "res" folder and I am hoping that the button will call on that pdf file. However it keeps coming up pdf not found? Is there something wrong with my code?

Button btn=(Button)findViewById(R.id.button1);

        btn.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v) {
           File file = new File("@Eng_Curr/Eng_Curr.pdf");
           Intent intent = new Intent(Intent.ACTION_VIEW);
           intent.setDataAndType(Uri.fromFile(file),"@Eng_Curr/Eng_Curr.pdf");
           intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
           startActivity(intent);
            }
        });

解决方案

Hi Folks so after taking all of your advice which is much appreciated I have found a work around for this. I used a swipe feature to swipe between png images and mViewFlipper along with SwipeGestureDetector. However one of the problems with this is memory shortage. I'm pretty sure it is down to the size of the png files but I may also need to find a way to terminate saved instances after each swipe. Still working on it and any suggestions would be helpful. Anyway hope this code helps.

public class English extends Activity {

    public class English extends Activity { 
    private static final int SWIPE_MIN_DISTANCE = 520;
    private static final int SWIPE_THRESHOLD_VELOCITY = 500;
    private ViewFlipper mViewFlipper;
    private Context mContext;

 private final GestureDetector detector = new GestureDetector(new SwipeGestureDetector());

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.infant_eng);
        mContext = this;
        mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);




        mViewFlipper.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(final View view, final MotionEvent event) {
                detector.onTouchEvent(event);
                return true;
            }
        });
    }

    class SwipeGestureDetector extends GestureDetector.SimpleOnGestureListener {

        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                // right to left swipe
                if (e1.getX() - e2.getX()> SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_in));
                    mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_out));
                    mViewFlipper.showNext();
                    return true;
                } else if (e2.getX() - e1.getX()> SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.right_in));
                    mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.right_out));
                    mViewFlipper.showPrevious();
                    return true;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            return false;
        }
    }
}

这篇关于按钮的onclick查看PDF文件的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆