小编Rit*_*itu的帖子

如何从网络向应用程序发送FCM通知

我正在开发基于Firebase数据库和存储的聊天应用程序.一切都运行正常,但现在我需要实施FCM,以便在应用程序处于后台或前台时接收应用程序通知.我找不到在PHP中实现的方法来监听firebase数据库中的任何更改,如果有任何更改,则将推送通知发送到应用程序.

有很多代码可以从PHP发送通知,但没有一个基于Firebase数据库,甚至官方文档都有我的共享主机不支持的Node.js指南.

我已经在我的应用程序端实现了FCM代码,该代码已经过Firebase控制台测试.

这是我的Firebase数据库结构 Firebase数据库结构

php firebase firebase-realtime-database firebase-cloud-messaging firebase-storage

13
推荐指数
4
解决办法
3万
查看次数

导航抽屉的碎片管理

应用层次结构 我正在开发一个应用程序,我只使用1个主要活动和多个片段,包括ViewPager,自定义视频/图像库,全屏片段(没有工具栏或底部导航按钮).我不确定这是好的做法,但我面临的问题很少.

上图是实际的App层次结构.在我面临的问题之后.

  1. 工具栏不会更改片段的标题,按下后退按钮或通过单击按钮或某个链接前进.
  2. 导航汉堡继续显示如果我改变成后箭头using: getSupportActionBar().setDisplayHomeAsUpEnabled(true);然后后箭头打开抽屉但不回到最后片段.
  3. 按下按钮或直接跳转到某个片段时的片段状态丢失.
  4. Fragment使用Single 执行所有任务是否是一种好习惯Activity.

我也在使用单个工具栏整个应用程序.Toolbar.xml

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/primary"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:contentInsetStartWithNavigation="0dp"
    android:fitsSystemWindows="true"
    app:layout_collapseMode="pin"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/toolbar_connections"
        android:visibility="visible"
        android:orientation="horizontal">
    <ImageView
        android:layout_width="35dp"
        android:layout_height="match_parent"
        android:id="@+id/appLogo"
        android:layout_gravity="center_vertical" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textSize="22sp"
            android:id="@+id/activityTitle"
            android:textColor="@color/primary_text"
            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/toolbar_chat"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:orientation="horizontal">

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="5dp"
            android:src="@drawable/baby"
            android:id="@+id/User_Image_Toolbar"/>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/User_Name_Toolbar"
                android:textSize="17sp"
                android:textStyle="bold"
                android:layout_marginBottom="5dp"
                android:text="My Name"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Online" …
Run Code Online (Sandbox Code Playgroud)

android toolbar android-fragments android-actionbar navigation-drawer

12
推荐指数
2
解决办法
758
查看次数

使用 httpurlconnection multipart/form-data 上传数组列表

我需要Arraylist在不使用任何库的情况下将图像上传到服务器。我正在使用Asynctask上传单个图像,它在 httpurlconnection multipart/form-data 的帮助下完美运行。现在我需要更改我的代码以使用上传任何类型的多个文件,Arraylist<String>但我的问题是现有代码FileinputStream不支持 arraylist,我不知道使用什么而不是Fileinputstream将 arraylist 上传到服务器,我不知道也想为此使用任何库。

public class multipart_test extends AsyncTask<Void,Void,String> {
    Context context;
    String Images;
    public static final String TAG = "###Image Uploading###";


    public multipart_test(Context context,String Upload_Images) {
        this.context = context;
        this.Images = Upload_Images;

    }

    @Override
    protected String doInBackground(Void... params) {
        BufferedReader reader;
        String WebPath = null;
        try {
            String lineEnd = "\r\n";
            String twoHyphens = "--";
            String boundary = "*****";
            int bytesRead, bytesAvailable, bufferSize;
            byte[] buffer;
            int …
Run Code Online (Sandbox Code Playgroud)

java android arraylist httpurlconnection android-asynctask

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

位置根据设备状态更新

我需要在ActivityRecognition Detect用户状态(每隔3分钟调用一次)之后获取用户的位置(通过fusionlocation API),如IN_VEHICLE,ON_FOOT,RUNNING等.

在每个事件上,我需要定期间隔后的用户位置例如:

如果用户仍然是,那么setInterval(5*60*60*1000);在5小时之前检查下一个位置更新.但ActivityRecognation将每3分钟调用一次.

如果用户正在运行,则setInterval(2*60*1000);在2分钟之前/之后检查下一个位置更新.但ActivityRecognation将每3分钟调用一次.

如果用户正在运行,则如果用户正在驾驶,则每隔1分钟发送一个位置,然后每15分钟发送一次位置.

我试图onConnected在类级别将boolean false设置为false和true.但它总是变成真实的,因为整个Intent服务在3分钟后被调用.

if (startLocationFirst){
requestLocatonSetting(5*60*60*1000,3*60*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY); 
  LocationAPIclient.connect();// RequestLocation and GoogleAPIClient won't call until device comes from another ActivityRecognation State running,walking etc. And keep Updating location every 5 hours.
              }
Run Code Online (Sandbox Code Playgroud)

问题我现在有

  • ActivityRecognation每3分钟获取一次用户状态,但它不应该进入startLocationFirst布尔值,直到它来自另一个ActivityRecognation状态并保持更新位置设置为内部startLocationFirst

这是带有FusedLocation的IntentService

public class Activity_Recognized_Service extends IntentService implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks, LocationListener {
    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for …
Run Code Online (Sandbox Code Playgroud)

java android location google-api activity-recognition

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

Android动画绘制字母表

我被困在对我来说有点困难的动画部分,我需要像这样绘制这个绿色标志。我尝试过这个Github 指南实现了我的要求,但是使用Path我只能在坐标的帮助下移动视图,而且我离我需要的结果还很远。我不确定从哪里开始从动画中获得所需的结果。我避免嵌入GIF和任何繁重的库来获得我的结果。请帮助制作这种动画,我知道通过代码获得这种动画非常困难。

任何帮助将不胜感激。谢谢

如果上面的视频链接不起作用,请检查这个:视频链接

java xml graphics animation android

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

NestedScrollView里面的Fragment(Viewpager)没有加载

我有片段与布局CoordinatorLayout与内部NestedScrollView和内nestedscrollview我有ViewPagerTabLayout同片段.标签是可见的,但与标签相关的片段未加载.

可见选项卡但不是片段

布局

                                                                                                            <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    android:background="?android:attr/colorBackground"
    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="match_parent">

        <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" -->


          <android.support.v4.view.ViewPager
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/ViewPagerImages"
              app:layout_collapseMode="parallax"
              app:layout_collapseParallaxMultiplier="0.7"
              android:scrollIndicators="top|right">

          </android.support.v4.view.ViewPager>


            <ProgressBar
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:id="@+id/Progress_Bar_Image"
                android:layout_gravity="center_horizontal|center_vertical"
                android:visibility="visible"
                 />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_gravity="right|top"
                android:layout_marginRight="30dp"
                android:layout_marginTop="30dp"
                android:background="@drawable/round_default"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="25sp"
                    android:text="1"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="25sp"
                        android:text="/5"/>


            </LinearLayout>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="200dp"
                android:layout_gravity="bottom"
                android:padding="15dp"
                >
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/unsa"
                    android:orientation="horizontal"
                    android:gravity="center">
                    <ImageView
                        android:id="@+id/user_S" …
Run Code Online (Sandbox Code Playgroud)

android adapter android-fragments android-viewpager android-tablayout

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

Imageview 没有显示圆角

在此处输入图片说明

我试图让我的布局像这样,但我无法像这样用圆角制作我的图像视图。它在 Android Studio 的布局编辑器中完美显示,但在实际设备中我得到了平角。我厌倦了 XML 和代码,但没有为我工作。请帮助我像这个示例图像一样制作我的布局。

我的布局文件

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:clickable="true"
    android:background="?android:attr/colorBackground"
    android:focusable="true">

    <androidx.constraintlayout.widget.ConstraintLayout

        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:paddingStart="5dp"
        android:paddingEnd="5dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true">

        <ProgressBar

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/User_CoverPhoto"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

        <ImageView

            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:layout_marginEnd="8dp"
            android:background="@drawable/round_shape_only"
            android:scaleType="centerCrop"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/User_CoverPhoto"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <ProgressBar

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/User_ProfilePictures"
            app:layout_constraintTop_toTopOf="parent"
            />
        <ImageView

            android:layout_width="230dp"
            android:layout_height="match_parent"
            android:background="@drawable/round_shape_only"
            android:scaleType="centerCrop"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/User_ProfilePictures"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:background="#40000000"
            android:backgroundTint="#CC000000"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Profile Picture"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent" …
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-imageview

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