小编Del*_*ian的帖子

Firestore仅更新一个字段

我有一个数据库.序列是:collections - document - hashmaps.例如:

users - 集合的名称

users.uid - 文档的名称

Hashmap文档由很多hashmaps用户数据Hashmap Hashmap等组成

Hashmap:用户名是密钥,电话,位置等是值.我只需要为一个用户名更新一个字段(位置),但无法理解这是怎么做到的?

我尝试了下一个方法(更新alex的电话号码):

User user = new User();
user.setPhone(131902331);

Map<String,RealmObject> userMap = new HashMap<>();
userMap.put("alex",user);

          mFirebaseFirestore
                  .collection("users")
                  .document(mFirebaseAuth.getUid())
                  .set(userMap, SetOptions.merge())
                  .addOnSuccessListener(new OnSuccessListener<Void>() {
                      @Override
                      public void onSuccess(Void aVoid) {
                          LOG.info("Success");
                      }
                  })
                  .addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          LOG.error("Failure "+e.toString());
                      }
                  });
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

android firebase google-cloud-firestore

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

REQUEST_IGNORE_BATTERY_OPTIMIZATIONS如何正确完成

我的IntentService任务处于前台模式,但在Android M +中,任务在Doze模式下停止.如果应用程序使用意图将自己设置为白名单,我会读取Google禁止的内容.但是如果我使用权限并检查GRANT或DENIED,我会得到授予的结果,但没有任何反应.我没有在白名单中看到我的应用.如何在未经禁止的白名单中添加应用程序?(我添加了许可AndroidManifest.xml)

if(Build.VERSION.SDK_INT>=23){
    int permissionCheck= ContextCompat
                    .checkSelfPermission(this, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);

    if(permissionCheck == PackageManager.PERMISSION_DENIED){

        //Should we show an explanation
        if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)){
            //Show an explanation
            final String message = "";
             Snackbar.make(coordinatorLayoutView,message,Snackbar.LENGTH_LONG)
                     .setAction("GRANT", new View.OnClickListener() {
                         @Override
                         public void onClick(View v) {
                             ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS }, PERMISSION_REQUEST_CODE);
                         }
                     })
                     .show();

                }else{
                    //No explanation need,we can request the permission
                    ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS }, PERMISSION_REQUEST_CODE);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

permissions android android-6.0-marshmallow

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

创建自定义 WebView

我在程序的不同部分有很多 WebView,但这些 WebView 彼此没有区别,这就是为什么我想创建一个具有必要设置的自定义 WebView。目前,WebView 不显示,但没有错误。难道我做错了什么?

public class MyWebView extends WebView {

    MyWebView mMyWebView;

    public MyWebView(Context context) {
        super(context);
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

     public MyWebView initView(Context context){
         LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         MyWebView view = (MyWebView) inflater.inflate(R.layout.custom_webview, this);
         view.getSettings().setJavaScriptEnabled(true) ;
         view.getSettings().setUseWideViewPort(true);
         view.getSettings().setLoadWithOverviewMode(true);
         view.getSettings().setDomStorageEnabled(true);
        return view;
    }
}
Run Code Online (Sandbox Code Playgroud)

custom_webview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <WebView
        android:id="@+id/custom_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

主要活动:

public class MainActivity extends AppCompatActivity {

  MyWebView mWebView;

   @Override
  protected void …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-webview

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

Android + Proguard + Apache POI

经过混淆后,有人能够使Apache POI库正常工作。我阅读了很多信息,尝试了不同的方法,但仍然收到错误:

a.a.b.a: Provider com.bea.xml.stream.EventFactory not found
org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.init(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.Package.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(Unknown Source)
at org.apache.poi.openxml4j.opc.OPCPackage.create(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

我将jar文件添加到libs文件夹中:poi-ooxml-schemas-3.12-20150511-a.jar和poi-3.12-android-a.jar。

我的proguard-rules.pro:

-dontwarn org.apache.**
-dontwarn org.openxmlformats.**
-dontwarn schemasMicrosoftComVml.**
-dontwarn org.w3.x2000.**
-dontwarn org.etsi.uri.**
-dontwarn com.microsoft.schemas.**
-dontwarn schemasMicrosoftComOfficeOffice.**
-dontwarn schemasMicrosoftComOfficeExcel.**
-dontwarn com.google.common.**

-keeppackagenames org.jsoup.nodes
-keepattributes *Annotation*, EnclosingMethod,Signature, JavascriptInterface
-keep class com.google.common.**

#Parcel
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *; …
Run Code Online (Sandbox Code Playgroud)

android proguard apache-poi android-proguard

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

无法将转储HPROF文件从Android Studio转换为MAT格式

当我尝试将android studio终端中的HPROF文件转换为MAT格式时:

1)hprof-conv [-z] d:/dump.hprof d:/outfile.hprof

2)hprof-conv d:/dump.hprof d:/outfile.hprof

我有相同的答案:

用法:hprof-conf [-z] infile outfile

-z:排除非应用堆,例如Zygote

为任一文件或两个文件指定' - '以使用stdin/stdout.

版权所有(C)2009 Android开源项目

该软件是根据Apache许可证2.0版("许可证")许可的源代码构建的.您可以在以下位置获取许可证副本

http://www.apache.org/licenses/LICENSE-2.0
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅此软件的相关NOTICE文件.

但是android平台工具中没有hprof-conf命令.

我该怎么做才能转换文件?

android hprof

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

ML Kit文本识别+西里尔字母

我正在尝试使用 Android 的 ML 套件文本识别西里尔文,但套件无法正确识别俄语?当我使用英文文本时一切正常。我可以改善我的结果吗?也许,我做错了什么吗?

PS 感谢创建此套件的人们,这很酷。

在此输入图像描述

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    cameraProviderFuture = ProcessCameraProvider.getInstance(context!!)

    cameraProviderFuture.addListener(Runnable {
        val cameraProvider = cameraProviderFuture.get()
        bindPreview(cameraProvider)
    }, ContextCompat.getMainExecutor(context))

    takePicture.setOnClickListener {
        imageCapture.takePicture(File(getVideoFilePath(context!!)),
                ContextCompat.getMainExecutor(context),
                object : ImageCapture.OnImageSavedCallback {
                    @RequiresApi(Build.VERSION_CODES.P)
                    override fun onImageSaved(file: File) {
                        startTextRecognition(file)
                    }
                    override fun onError() {}
                })
    }
}

private fun startTextRecognition(textImage: File) {
    val recognizer = FirebaseVision.getInstance().onDeviceTextRecognizer
    recognizer.processImage(FirebaseVisionImage.fromFilePath(context, textImage.toUri()))
            .addOnSuccessListener {
                processTextRecognitionResult(it)
            }.addOnFailureListener {
                it.printStackTrace()
            }
}

  private fun processTextRecognitionResult(text: FirebaseVisionText) {
    var str = ""
    val …
Run Code Online (Sandbox Code Playgroud)

android firebase-mlkit

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