小编Abh*_*rya的帖子

AOA USB连接问题

我一直在努力使在链接中指定USB连接这里,并成功地实现了它.它的工作正常接受它经常断开连接.我从这个链接和这个链接知道android OS中有一个错误,没有USB连接事件的广播事件.我已经实现了一个接收器来获取USB断开事件,这并不是太重要.此外,我引用链接创建与USB的稳定连接,即USB连接后开始数据通信没有任何损失.当应用程序中存在单个活动或单个屏幕时,整个过程正常工作.

对于多屏幕这个连接有问题,即连接不稳定,我在应用程序中有多个屏幕,我可以随时通过USB在任何活动中接收数据.所以我有2个问题,如果可能的话,我正在寻找一些代码的答案

  1. 如何在多个屏幕上通过Android中的串行USB连接设备进行稳定连接
  2. 如何在多个屏幕上摆脱应用程序中的这种频繁断开连接问题

任何帮助都会很棒

编辑:

我正在添加我负责与usb通信的服务,并启动一个连续接收数据的线程

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.hardware.usb.UsbManager;
import android.os.IBinder;
import arya.omnitalk.com.usb.R;
import arya.omnitalk.com.usb.constants.FileReadingWritingConstants;
import arya.omnitalk.com.usb.constants.GeneralConstant;
import arya.omnitalk.com.usb.constants.UsbDataWriterConstants;

import com.hoho.android.usbserial.driver.UsbSerialProber;

public class UsbCommunicationService extends Service{

    public static ArrayList<String> _dataArray = new ArrayList<String>();
    private Thread mCommunicationThread = null;

    private class ReadThread implements Runnable {
        @Override
        public void run() {

            while (mCommunicationThread!= null && …
Run Code Online (Sandbox Code Playgroud)

java usb android

5
推荐指数
1
解决办法
1667
查看次数

Android M快捷方式安装/卸载重复

我试图通过服务为我的应用程序创建一个快捷方式.以下代码正在处理SDK <= 21,但它无法正常工作SDK = 23

快捷方式的创建方式是这样完成的:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
        shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked on the created shortcut
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

        Intent addIntent = new Intent();
        addIntent.putExtra("duplicate", false);
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.application_icon));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

        sendBroadcast(addIntent);
Run Code Online (Sandbox Code Playgroud)

SDK <= 21创建快捷方式中,如果已存在,则不会创建其他实例.

SDK = 23快捷方式将仅如果我按创建shorcut并再次尝试创建快捷方式.如果我重新启动该设备,然后再次尝试创建快捷方式复制或.

我尝试先卸载快捷方式,但没有成功SDK 23,如下所示:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
        shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-6.0-marshmallow

4
推荐指数
1
解决办法
1448
查看次数

Android:捕获的图像未显示在图库中(Media Scanner意图不起作用)

我有以下问题:我正在开发一个应用程序,用户可以在其中拍照(附加到帖子),图片保存到外部存储.我希望这张照片也出现在图片库中,我正在使用Media Scanner意图,但它似乎不起作用.我在编写代码时遵循官方Android开发人员指南,所以我不知道出了什么问题.

部分代码:

用于捕获图像的意图:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Toast.makeText(getActivity(), ex.getMessage(), Toast.LENGTH_SHORT).show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, …
Run Code Online (Sandbox Code Playgroud)

java media android image android-intent

3
推荐指数
2
解决办法
5325
查看次数

没有标题动画的CollapsingToolbarLayout

我正在努力CollapsingToolbarLayout.我不知道在工具栏中固定标题的方法.

有没有简单的方法来实现这一目标?

android toolbar android-collapsingtoolbarlayout

3
推荐指数
1
解决办法
1980
查看次数

为什么当 CollapsingToolbarLayout 完全折叠时 NestedScrollView 停止滚动?

我正在使用collapsingToolbarlayoutwithnestedscrollview并且它工作正常,直到collapsingToolbarlayout完全崩溃并actionbar显示。这里nestedscrollview停止滚动,一些项目仍然隐藏。

这是我的 xml 文件

    <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            >

            <FrameLayout
                android:id="@+id/topLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                >

                <ImageView
                    android:id="@+id/BigThumbnailImage"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:adjustViewBounds="true"
                    android:fitsSystemWindows="true"
                    android:src="@drawable/bg_health_news"
                    android:scaleType="fitXY" />

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1"
            >

            <include
                android:layout_width="match_parent"
                android:layout_height="0dp"
                layout="@layout/place_item_details_views"
                android:layout_weight="1"
                /> …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout nestedscrollview

3
推荐指数
1
解决办法
3194
查看次数

android 2.3.3中的CREATE TABLE android_metadata失败

我正在使用我正在使用SQlite数据库的应用程序.我的应用程序在每个操作系统版本和所有模拟器中运行良好,但它只会在操作系统版本2.3.3的设备中产生问题.我收到CREATE TABLE android_metadata消息和我的数据库代码崩溃.

我正在使用谷歌Nexus与Android OS 2.3.3

请告诉我实际问题是什么以及如何解决此设备相关问题.我也在下面发布我的代码:

public class ECatalogueDatabase {

    private static final String DB_PATH = "/data/data/com.weg.ecatalogue/databases/";
    public static final String DATABASE_NAME = "ECatalogue";
    public static final String DATABASE_TABLE = "T_Electrical";
    public static final int DATABASE_VERSION = 1;

    public static final String KEY_ROWID="id";
    public static final String KEY_PRODUCT_LINE="productline";

    public static final String KEY_VOLTAGE="voltage";
    public static final String KEY_OUTPUTHP="outputhp";

    public static final String KEY_FRAME="frame";
    public static final String KEY_RPM="rpm";

    private Context context=null;
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db; …
Run Code Online (Sandbox Code Playgroud)

sqlite android

1
推荐指数
1
解决办法
6654
查看次数

如何在android中向多个收件人发送电子邮件?

我是安卓新手。请帮我。我无法向多个收件人发送电子邮件。这是我的代码。

public class SendEmailActivity extends Activity{

EditText subject_ed,message_ed;
TextView subject_tv,message_tv;
Button send_btn;

 ArrayList<String> emailList;
 ArrayList<Integer> idList;
 int eventId;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contacts_email_sms_layout);
    setupViews();
    Intent intent = getIntent();
    Bundle b = intent.getExtras();
    eventId =  b.getInt("EventId");//event id
    idList = b.getIntegerArrayList("IdList");//list of Ids
    emailList = b.getStringArrayList("EmailList");//list of email ids
    buttonListeners();
}

public void setupViews()
{
    subject_ed = (EditText)findViewById(R.id.ed_subject_email);
    message_ed = (EditText)findViewById(R.id.ed_msg_body);
    subject_tv = (TextView)findViewById(R.id.tv_subject_email);
    message_tv = (TextView)findViewById(R.id.tv_msg_body);
    send_btn = (Button)findViewById(R.id.btn_send_sms_email);
}               

public void buttonListeners() …
Run Code Online (Sandbox Code Playgroud)

email android

1
推荐指数
1
解决办法
4420
查看次数

Watson语音到文本服务如何在java中返回英语以外的语言

当我尝试将STT设置为"zh-CN_BroadbandModel"的STT Java代码时,无法获得预期的结果.

这是我的示例代码:

public static void main (String[] args) {

    SpeechToText service = new SpeechToText();
    service.setUsernameAndPassword(USERNAME, PASSWORD);

    File file = new File("C:/IBM/Watson/APIs/speech-to-text/test.wav");

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("audio", file);
    params.put("content_type","audio/wav");
    params.put("model", "zh-CN_BroadbandModel");

    SpeechResults transcript = service.recognize(params);

    System.out.println(transcript);
}
Run Code Online (Sandbox Code Playgroud)

SpeechResult如下:

{"results": [{
      "final": true,
      "alternatives": [
        {"transcript": "?? ? ? ? ?? ? ? ? ?? ??? ? ??? ?? ? ? ?? ?? ? ??? ? ?? ? ?? ?? ? ?? ? ?? ? ?? ?? ? …
Run Code Online (Sandbox Code Playgroud)

speech-to-text chinese-locale ibm-watson ibm-cloud

1
推荐指数
1
解决办法
530
查看次数