小编Sco*_*ott的帖子

如何使用Google Play服务中的新条形码API捕获条形码值?

我一直在玩新的Google Barcode API中的示例代码.它将条形码和条形码值叠加在条形码的实时摄像机上.(也面临)

我无法告诉如何将条形码值返回到我的应用程序.A)如何判断检测事件何时发生以及B)如何访问ravValue以便在我的应用程序的其他部分中使用.有人能帮忙吗?

https://developers.google.com/vision/multi-tracker-tutorial

https://github.com/googlesamples/android-vision

更新: 在@ pm0733464的答案的基础上,我在Tracker类中添加了一个回调接口(称为onFound),我可以在Activity中访问该接口.调整Google多跟踪器示例:

GraphicTracker:

class GraphicTracker<T> extends Tracker<T> {
    private GraphicOverlay mOverlay;
    private TrackedGraphic<T> mGraphic;
    private Callback mCallback;

    GraphicTracker(GraphicOverlay overlay, TrackedGraphic<T> graphic, Callback callback) {
        mOverlay = overlay;
        mGraphic = graphic;
        mCallback = callback;
    }

    public interface Callback {
        void onFound(String barcodeValue);
    }

    @Override
    public void onUpdate(Detector.Detections<T> detectionResults, T item) {
        mCallback.onFound(((Barcode) item).rawValue);
        mOverlay.add(mGraphic);
        mGraphic.updateItem(item);
    }
Run Code Online (Sandbox Code Playgroud)

BarcodeTrackerFactory:

class BarcodeTrackerFactory implements MultiProcessor.Factory<Barcode> {
    private GraphicOverlay mGraphicOverlay;
    private GraphicTracker.Callback mCallback;

    BarcodeTrackerFactory(GraphicOverlay graphicOverlay, GraphicTracker.Callback callback) …
Run Code Online (Sandbox Code Playgroud)

android google-play-services google-vision

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

这些Android logcat警告意味着什么?

它似乎没有影响我的应用程序中的任何东西...... 我第一次使用Android支持库(我的项目到目前为止还没有使用支持库),但这是一个新项目,还没有太多的自定义方式.活动由Android Studio 0.9.2生成并实现导航抽屉.

在运行Android 4.4.2的Verizon Samsung Galaxy SIII上运行此功能.项目设置为minSDK为15,目标SDK为21.

11-21 10:31:18.204    7095-7095/com.myapp.debug I/dalvikvm? Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
11-21 10:31:18.204    7095-7095/com.myapp.debug W/dalvikvm? VFY: unable to resolve virtual method 11400: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-21 10:31:18.204    7095-7095/com.myapp.debug D/dalvikvm? VFY: replacing opcode 0x6f at 0x0000
11-21 10:31:18.204    7095-7095/com.myapp.debug I/dalvikvm? Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
11-21 10:31:18.204    7095-7095/com.myapp.debug W/dalvikvm? VFY: unable to resolve virtual method 11406: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-21 10:31:18.204    7095-7095/com.myapp.debug D/dalvikvm? VFY: replacing opcode 0x6f at …
Run Code Online (Sandbox Code Playgroud)

android logcat android-support-library android-studio

18
推荐指数
2
解决办法
2万
查看次数

找不到方法onClick_Foo(View) - 第一次在Android Lollipop上运行

我有一个大约一岁的应用程序,在测试版的Play商店,已经经历了几十次修订.突然间我收到了一个错误:

无法在活动类android.view.ContextThemeWrapper中找到onClick_Foo(View)方法,用于视图类android.widget.Button上的onClick处理程序,其id为'Foo_Button'

我在XML中定义的7个按钮中的每个按钮上都出现此错误.从昨天起我将appcompat-v7从21.0.3更新到22.0.0,但也是第一次将我的测试设备从KitKat升级到Lollipop.

我已经仔细检查了拼写,大写,没有通常的嫌疑人解释这一点.这是相关代码的示例.如果您觉得更有帮助,请告诉我.(该活动有915行代码和xml 186,所以不要求整个事情).在运行Lollipop 5.0.1的Verizon Note 4上进行测试

activity_pick.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:theme="@style/AppTheme"
    tools:context="com.myapp.Pick"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Ratings_Button"
            android:textSize="16dp"
            android:text="@string/Pick_Ratings_Button"
            android:onClick="onClick_Ratings"
            android:background="@android:drawable/btn_default"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

Pick.java:

public class Pick_Restaurant extends ActionBarActivity {
    public void onClick_Ratings (View v) {
        Intent intent = new Intent(mContext, Ratings.class);
        startActivityForResult(intent,RATINGS);
    }
}
Run Code Online (Sandbox Code Playgroud)

的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 59
    versionName "0.6.4"
}

...

dependencies { …
Run Code Online (Sandbox Code Playgroud)

android onclick android-5.0-lollipop

18
推荐指数
2
解决办法
2万
查看次数

尝试在Android Studio中实现getSharedPreferences时出现"无法解决方法"错误

我正在尝试创建一个类KeyValueDB,它存储与SharedPreferences交互的方法,但是我遇到了一个只是定义类的问题.我想要构造函数做的就是使用正确的文件名存储一个sharedPreferences对象,但我得到一个"无法解析方法"的getSharedPreferences(java.lang.String,int)'

我传递一个字符串和一个int ...我不确定我做错了什么.感谢任何帮助!

package com.farmsoft.lunchguru.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONException;

/**
 * Created by sxs on 4/28/2014.
 */
public class KeyValueDB {
    private SharedPreferences sharedPreferences;

    public KeyValueDB(String prefName) {
        sharedPreferences = getSharedPreferences(prefName, Context.MODE_PRIVATE);
    }
Run Code Online (Sandbox Code Playgroud)

java android sharedpreferences

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

Android:在我的Java代码中放入敏感字符串是否安全?

我的应用程序使用了许多我无法让用户看到的API密钥和URL.我一直把它们直接放在代码中,有时嵌入在使用它们的方法中,有时在一个名为MyVals的类中,它存储常用的字符串和数字.

例如:

public class MyVals {

    private LGVals(){}

    public static final String DB_URL = "https://mydb.dbprovider.org/";
    public static final String DB_Key = "klJF*(oh8iyhkkde";
    public static final String TableKey_UserList = "o9w6owifhayf98fnwihj";

}
Run Code Online (Sandbox Code Playgroud)

这样安全吗?如果我用Proguard创建我的APK会有所不同吗?这是最好的做法是什么?

java encryption android proguard code-access-security

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

Android logcat中的这些数字是什么意思?

10-21 10:37:32.821  18142-18297/com.myapp.debug D/[111] SqLiteHelper insertArrayList? Start
10-21 10:37:33.422  18142-18291/com.myapp.debug D/[128] SqLiteHelper insertArrayList? Finish
10-21 10:37:33.452  18142-18142/com.myapp.debug D/[89] Screen1 onPause? SQLite db closing
Run Code Online (Sandbox Code Playgroud)

这些是我的Android应用日志中的典型行.

  1. 时间(10月21日上午10:37)
  2. 由破折号分隔的神秘数字
  3. 应用程序包(com.myapp.debug)
  4. 日志类型(调试)
  5. 标题(lineNum,Activity&Method)
  6. 身体

所以这些神秘的数字 - 他们是线程ID吗?用户ID?进程ID?为什么他们有时会改变?为什么有两个有时相同?

更新:调用"Log.d(Header,Body)"功能.使用Android Studio.

android logcat

9
推荐指数
2
解决办法
2981
查看次数

在升级到v22之后,signingConfigs标记在build.gradle中给出了一个Lint错误

我在build.gradle(app)文件中有以下代码:

signingConfigs {
    release {
        storeFile file("D:\\Android\\keystore\\myApp.jks")
        storePassword "myStorePw"
        keyAlias "myKeyAlias"
        keyPassword "MyKeyPw"
    }
}
Run Code Online (Sandbox Code Playgroud)

我刚刚升级到targetSdkVersion = 22,这意味着将SDK和构建工具升级到22.现在整个部分在Android Studio(141.1793788)中以黄色突出显示,并显示以下消息:

'signingConfigs' cannot be applied to '(groovy.land.Closure<com.android.build.gradle.internal.dsl.SigningConfig>)'
Run Code Online (Sandbox Code Playgroud)

我需要知道的v22有没有变化?我找不到文档.

groovy android lint gradle android-studio

9
推荐指数
2
解决办法
2280
查看次数

Android:广播ACTION_MY_PACKAGE_REPLACED从未收到过

我的应用程序运行的服务在设备重新启动或重新安装(更新)应用程序时终止.我添加了两个广播接收器来捕获这些事件 - BOOT_COMPLETED和ACTION_MY_PACKAGE_REPLACED.

ACTION_MY_PACKAGE_REPLACED接收器似乎不起作用.这就是我所拥有的:

AndroidManifest.xml中:

    <receiver android:name=".RebootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
    <receiver android:name=".ReInstallReceiver">
        <intent-filter>
            <action android:name="android.intent.action.ACTION_MY_PACKAGE_REPLACED"/>
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

RebootReceiver:

public class RebootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Logg.d("Reboot completed. Restarting service");
        context.startService(new Intent(context, MyService.class));
    }
}
Run Code Online (Sandbox Code Playgroud)

ReInstallReceiver:

public class ReInstallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Logg.d("App Upgraded or Reinstalled. Restarting service");
        context.startService(new Intent(context, MyService.class));
    }
}
Run Code Online (Sandbox Code Playgroud)

运行minSdk = 16; 在运行KitKat的Galaxy S3上进行测试.通过检查我的服务是否在"设置/应用程序"中运行来测试成功,它在重新启动时执行,但不重新安装.

我已经考虑了以下注释,其中说在Android Studio 1.0+中,清单合并意味着我无法将两个接收器合并为一个类.请参阅ACTION_MY_PACKAGE_REPLACED未收到,并且对于具有相同名称但内容不同的接收者,Android清单合并失败

android broadcastreceiver android-broadcast android-studio

6
推荐指数
3
解决办法
7256
查看次数

Android通知操作 - Intent Extra未按预期工作

我正在notification用多个动作创建一个.我正在用它broadcast intents来表达一个被推动并采取具体行动的人.有4个按钮,我创建了4个单独的意图.每个都有相同的Action字符串,但不同StringExtra.

Intent intNow = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_NOW);
    Intent intEmail = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_EMAIL);
    Intent intLater = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_LATER);
    Intent intNever = new Intent(mThis, MyReceiver.class).setAction(actionNotify).putExtra("button", ACT_NEVER);

    Notification.Builder myRatingNotification = new Notification.Builder(mThis)
            .setContentTitle(title)
            .setContentText(text)
            .setSmallIcon(R.mipmap.ic_launcher)
            .addAction(0, mThis.getString(R.string.Rate_Act_Now), PendingIntent.getBroadcast(mThis, 0, intNow, PendingIntent.FLAG_UPDATE_CURRENT))
            .addAction(0, mThis.getString(R.string.Rate_App_Email), PendingIntent.getBroadcast(mThis, 0, intEmail, PendingIntent.FLAG_UPDATE_CURRENT))
            .addAction(0, mThis.getString(R.string.Rate_Act_Later), PendingIntent.getBroadcast(mThis, 0, intLater, PendingIntent.FLAG_UPDATE_CURRENT))
            .addAction(0, mThis.getString(R.string.Rate_Act_Never), PendingIntent.getBroadcast(mThis, 0, intNever, PendingIntent.FLAG_UPDATE_CURRENT))
            .setAutoCancel(true);

    Notification notification = new Notification.BigTextStyle(myRatingNotification).bigText(text).build();
    ((NotificationManager) mThis.getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification);
Run Code Online (Sandbox Code Playgroud)

因此,通知已成功创建.按钮在那里.但无论我推动哪一个,传递给它的额外receiver内容始终是最后定义的动作.也就是说,在上面的例子中,每个按钮返回一个等于的字符串Extra …

android android-intent android-notifications

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

Android Studio即时运行 - 覆盖并重建完整应用

到目前为止,我很喜欢Android Studio 2.0的Instant Run功能.对于当前活动的小调整,它很棒.但是,有时我需要在之前的活动中进行调整,而Instant Run要么不应用该更改,要么可能只是不重新运行之前的活动.我希望能够将Instant Run作为一个快速选项,但有时只是想告诉AS重新加载完整的应用程序而不使用Instant Run.

有快速的方法吗?我在某个地方看到有一个三步检查清单 - 停止,重建,调试.但即使这似乎没有用,显然比按下单个按钮的旧方法慢.

android-studio instant-run

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