我根据此代码将onLongPress和onDoubleTap操作放在按钮上:
...
GestureDetector detector = new GestureDetector(this, new TapDetector());
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
detector = new GestureDetector(this, new TapDetector());
...
}
private class TapDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
// Do something
return true;
}
@Override
public void onLongPress(MotionEvent e) {
// Do something
}
}
Button incomeButton = (Button) findViewById(R.id.income);
button.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
在onDoubleClick上点击并执行后,我总是看到onLongPress被解雇了.这种违反直觉的行为以及如何避免这种行为的原因是什么?
更新 我已经更改了我的源代码更具体
public class MainActivity extends …Run Code Online (Sandbox Code Playgroud) 我的应用程序使用Java类RandomAccessFile通过SeekableByteChannel接口的实现随机读取/写入SD卡上的文件.现在我需要使用新的Lollipop API为Android 5.0重写它.
我找到了唯一的阅读方式:
InputStream inputStream = getContentResolver().openInputStream(uri);
Run Code Online (Sandbox Code Playgroud)
和写:
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
Run Code Online (Sandbox Code Playgroud)
从/到新API中的文件.
我希望能够在某个随机位置设置通道,并将字节读/写到该位置.是否可以在新的SDK 21中执行此操作?新的SDK是否意味着获取频道:
FieInputChannel fieInputChannel = fileInputStream.getChannel();
FieOutputChannel fieOutputChannel = fileOutputStream.getChannel();
Run Code Online (Sandbox Code Playgroud)
或其他一些方法?
filechannel android-sdcard randomaccessfile android-5.0-lollipop documentfile
我想将我的应用程序在xlarge设备上的使用和其他设备上的使用分开,将layout_width参数限制为xdge的720dp.为此我创建了values/attrs.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<attr name="layoutWidth" format="reference|dimension" />
</resources>
Run Code Online (Sandbox Code Playgroud)
使用自定义参数layoutWidth将其设置为
android:layout_width="?layoutWidth"
Run Code Online (Sandbox Code Playgroud)
Furtner,我需要在values-xlarge和values目录中为xlarge和普通设备指定两个themes.xml文件 :
值-XLARGE /的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
<item name="layoutWidth">720dp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
值/的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
<item name="layoutWidth">What should I write here!?</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
那么,如何在这个地方对Android"fill_parent"参数进行参考呢?好像是@android:layout_width/fill_parent,但是我编译错误:
No resource found that matches the given name (at 'layoutWidth' with value '@android:layout_width/fill_parent').
Run Code Online (Sandbox Code Playgroud) 我正在使用 AS 3.1gradle-4.5-all.zip和 main build.gradle:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Run Code Online (Sandbox Code Playgroud)
一个app-level build.gradle看起来像以下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 27
versionCode 6
versionName "1.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'ch.acra:acra:4.6.1'
implementation 'commons-validator:commons-validator:1.5.0'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation …Run Code Online (Sandbox Code Playgroud) 我有一部 Android 6.0 手机,配有内部存储器、可移动 SD 卡和插入手机中的 USB OTG(带微型 USB 插孔的笔式驱动器)。Android设备中弹出可移动SD卡和USB OTG:“设置”->“存储和USB”。我可以在该设备中安装可移动SD卡和USB OTG。例如,我安装了可移动 SD,并希望将此事件与 USB OTG 的安装区分开来。我可以在接收器中执行的唯一操作
<receiver
android:name=".receiver.RemovableMediaReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_EJECT"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<data android:scheme="file"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
挂载时为android.intent.action.MEDIA_MOUNTED,挂载的 SD 卡的根目录路径作为此操作的额外内容 - /storage/A13D-EF43。USB OTG 安装事件也是如此。唯一的区别在于安装的 USB OTG 的名称 - 路径是/storage/BD76-24ED。
如果我在安装之前没有 API 调用来获取 SD 或 USB OTG 的名称,以便将其与android.intent.action.MEDIA_MOUNTED中的额外(路径)进行比较,我如何了解安装了哪种媒体 - SD 或 USB OTG ?
android usb-drive android-sdcard removable-storage android-broadcastreceiver
我有一个设置类型"message/rfc822"的问题,意图在Android模拟器上发送带有文件附件的电子邮件.我必须使用setType("message/rfc822"),因为文件没有标准的MIME类型(sqlite数据库),我试图避免选择列表中的很多应用程序供用户选择.对于2.3.3之前的所有API级别,我有一个错误:
java.lang.RuntimeException:
Unable to start activity ComponentInfo{my.cashwatcher/my.cashwatcher.SendEmailActivity}:
android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.SEND typ=message/rfc822
(has extras) }
Run Code Online (Sandbox Code Playgroud)
在API Level 2.3.3的情况下,代码工作正常并且不会出现错误.这是Android模拟器还是旧API的问题!?
码:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{appPrefs.getEmail("email")});
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), DATABASE_PATH)));
sendIntent.putExtra(Intent.EXTRA_TEXT, "body_of_email");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "APPLICATION_NAME");
startActivityForResult(sendIntent, EMAIL_SEND_RESULT);
Run Code Online (Sandbox Code Playgroud) android ×5
attributes ×1
documentfile ×1
double-click ×1
email ×1
filechannel ×1
gradle ×1
layout ×1
lint ×1
usb-drive ×1