简体   繁体   English

Android代码可在2.3上使用,但不能在4.0上使用

[英]Android Code Works On 2.3 But Not On 4.0

I have written the following code designed for API version 2.3.3 minimum and works fine on an emulator designed for that. 我编写了以下针对API 2.3.3最低版本设计的代码,并且在为此设计的仿真器上可以正常工作。 I have just tried testing the same code on API 4.0 and the onFling gestures I've implemented to control the app don't work. 我刚刚尝试在API 4.0上测试相同的代码,但为控制应用程序而实现的onFling手势不起作用。 They don't even seem to be called. 他们甚至似乎都不被称为。

Here is the code. 这是代码。

package com.mystraldesign.memorable;

import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;
import com.mystraldesign.memorable.PassGen;

public class MemorableActivity extends Activity implements android.view.GestureDetector.OnGestureListener,OnDoubleTapListener  
{
    //Define text views
    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;

    //Previous password holder
    private String prevPass;

    //Gesture Detectors
    private GestureDetector gTap; 

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        gTap  = new GestureDetector(this,(android.view.GestureDetector.OnGestureListener) this);

        //Remove title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);




        //Define textView
        textView1 = (TextView) findViewById(R.id.textView1);
        textView2 = (TextView) findViewById(R.id.textView2);
        textView3 = (TextView) findViewById(R.id.textView3);
        textView4 = (TextView) findViewById(R.id.textView4);

        //Load font file
        Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf"); 

        //Set various textViews to font
        textView1.setTypeface(type);
        textView2.setTypeface(type);
        textView3.setTypeface(type);
        textView4.setTypeface(type);

        prevPass = "Memorable";

    }



    //Password call
    public void newPass()
    {
        //Store Return
        String retn = "";
        PassGen passWord = new PassGen();


        //Generate password
        try 
        {
            retn = passWord.passwordGen(this);
        } 
        catch (IOException e) 
        {

            //Message about Error
            Context context = getApplicationContext();
            CharSequence text = "Ooops Something Went Wrong!";
            int duration = Toast.LENGTH_SHORT;

            //Display message
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();

            textView1.setText("Memorable");


            e.printStackTrace();
        }

        //Update prevPass
        prevPass = textView1.getText().toString();

        textView1.setText(retn);
    }









    /*--------------------------------------*/
    /*Additional gesture code below. */
    /* */
    /*J. Krawczyk 3/5/12*/
    /*--------------------------------------*/



    public boolean onTouchEvent(MotionEvent me){ 
        this.gTap.onTouchEvent(me);
       return super.onTouchEvent(me); 
      }



    public boolean onDown(MotionEvent e) {

      return false;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
          float velocityY) 
  {

    String test = textView4.getText().toString();
    if ((velocityX == 0) && (velocityY > 0))
    {

        //Call new password generation or generate random if set
        if(test.equals("Memorable"))
        {
            newPass();
        }
        else if(test.equals("Random"))
        {
            //create new password method
            PassGen pass = new PassGen();

            //Set password
            textView1.setText(pass.randomPassword());
        }
    }
    else if((velocityX == 0) && (velocityY < 0))
    {
        textView1.setText(prevPass);
    }
    else if((velocityY == 0) && (velocityX > 0))
    {

        if(test.equals("Memorable"))
        {
            textView4.setText("Random");
        }
        else if(test.equals("Random"))
        {
            textView4.setText("Memorable");
        }   
    }


    return false;
  }


    public void onLongPress(MotionEvent e) 
    {

    }


    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
      float distanceY) {

     return false;
    }


    public void onShowPress(MotionEvent e) {

    }

    public boolean onSingleTapUp(MotionEvent e) {

     return false;
    }


    //Method to copy password - Depreciated
    public boolean onDoubleTap(MotionEvent e) {

     return false;
    }

    //Method to copy password
    public boolean onDoubleTapEvent(MotionEvent e) {

        //clipboard shite
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
        clipboard.setText(textView1.getText());

        //Message about coping
        Context context = getApplicationContext();
        CharSequence text = "Password has been copied to clipboard.";
        int duration = Toast.LENGTH_SHORT;

        //Display message
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

      return false;
    }



    public boolean onSingleTapConfirmed(MotionEvent e) {

     return false;
    }





}

The console keeps saying it fails to install but it appears on emulator and runs. 控制台一直说它无法安装,但出现在模拟器上并运行。 The same happens when testing on an actual 4.0 device. 在实际的4.0设备上进行测试时,也会发生相同的情况。

2012-05-03 05:57:06 - Emulator] 2012-05-03 05:57:06.471 emulator-arm[5445:1107] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
[2012-05-03 05:57:06 - Emulator] emulator: emulator window was out of view and was recentered
[2012-05-03 05:57:06 - Emulator] 
[2012-05-03 05:57:06 - Memorable] New emulator found: emulator-5554
[2012-05-03 05:57:06 - Memorable] Waiting for HOME ('android.process.acore') to be launched...
[2012-05-03 05:59:24 - Memorable] HOME is up on device 'emulator-5554'
[2012-05-03 05:59:24 - Memorable] Uploading Memorable.apk onto device 'emulator-5554'
[2012-05-03 05:59:26 - Memorable] Installing Memorable.apk...
[2012-05-03 06:01:34 - Memorable] Failed to install Memorable.apk on device 'emulator-5554!
[2012-05-03 06:01:34 - Memorable] (null)
[2012-05-03 06:01:34 - Memorable] Failed to install Memorable.apk on device 'emulator-5554': EOF
[2012-05-03 06:01:34 - Memorable] com.android.ddmlib.InstallException: EOF
[2012-05-03 06:01:34 - Memorable] Launch canceled!

EDITED: 编辑:

It now runs and installs on all AVD's (2.3.3 - 4.0) but the gestures still only work on 2.3.3 它现在可以运行并安装在所有AVD(2.3.3-4.0)上,但手势仍然仅在2.3.3上有效

I have few suggestions for you, 我对你没有什么建议,

1) You first open your avd and wait until its get loaded completely and then run your apk. 1)您首先打开avd,然后等待其完全加载,然后运行apk。

2) change your setContentView(tv); 2)更改您的setContentView(tv); by this.setContentView(tv); 通过this.setContentView(tv);

3) close/delete your other old AVD 3)关闭/删除其他旧的AVD

4) If you got device with you, Test on it.. 4)如果设备随身携带,请对其进行测试。


Links to reffer this and this 链接

似乎手势错误未得到识别是由于我使用速度来确定运动,但在Android 4.0上受到了更好的控制,因此从未达到VelocityX = 0的条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android:ContentResolver在4.0上有效,但在2.3上无效 - android: ContentResolver works on 4.0 but not on 2.3 Android主要XML在2.3和4.0上的工作方式有所不同 - android main XML works diffrent on 2.3 and 4.0 在Android上捕获媒体按钮> = 4.0(适用于2.3) - Capture media button on Android >=4.0 (works on 2.3) Android 4.0中的类无响应-在2.3及以下版本中有效 - No response from class in Android 4.0 - works in 2.3 and below ActionBar - Android平板电脑2.3和4.0 - ActionBar - Android Tablet 2.3 and 4.0 Android应用程序只能在2.3上运行,而不能在4.0上运行 - Android app working on 2.3 but not on 4.0 Phonegap应用程序在运行Android 4.0时引发错误,但在Android 2.3及更低版本上可以正常运行 - Phonegap application throws error running Android 4.0, but works fine on Android 2.3 and below SHOUTCast Streaming Breaks in 4.0+,适用于2.3 - SHOUTCast Streaming Breaks in 4.0+, works in 2.3 Android我的应用程序可以在2.3上运行,但即使在4.0上也无法启动 - Android My application works on 2.3 fine but doesn't start even on 4.0 在Android 2.3和Android 4.0上联系photo uri - Contacts photo uri on Android 2.3 and Android 4.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM