• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

updating listView as data is received

So I'm attempting to write my first android application to support another project I'm working on. I send out a command to a USB attached device. The data packets are sent back over the wire, received, parsed, added to a database, and supposed to be added to an adapter in order to display in a list view. I attempted to follow instructions I found on a skill share video in order to implement the adapter. I was able to get the application from skill share working, an rss feed, but I'm attempting to make the same functionality work, but as data comes in and stored into the database, the adapter is updated to display the most recent data on the list view.

I have the buttons, send and receive, and a couple other things working in the main activity thread. As I receive data from the attached device I'm adding packets to a Queue.

Java:
@Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case UsbService.MESSAGE_FROM_SERIAL_PORT:
                    String packet = (String) msg.obj;

                    mActivity.get().dataPacket.append(packet);

                    if(lastCMD.equals("R07") || lastCMD.equals("R08" ))
                    {

                        if(mActivity.get().dataPacket.length() > 455)
                        {
                            String data = mActivity.get().dataPacket.toString();

                            data = data.replaceAll("[\\^\\*:]", "");

                            String[] split = data.split("\\r?\\n");

                            for(int i = 0; i < split.length; i++)
                            {

                                mActivity.get().dataR.add(split[i]);
                            }
                        }
                    }
...

I have another class running as its own thread. This thread handles the data that's stored into the Queue. If the Queue has data it will follow the operations to parse the packet lines and add them to the database.

Java:
class OperationThread extends Thread
{

    private MainActivity obj;

    private String data;
    private String time;
    private String temp;
    private String conc;
    private String batchNum;
    private String fileNum;
    private float temporary;

    SensorRecord record;

    OperationThread(MainActivity obj)
    {

        this.obj = obj;
    }

    public void run()
    {

        try
        {
            Thread.sleep(500);
        } catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        super.run();

        while (!Thread.currentThread().isInterrupted())
        {

            if(!obj.dataR.isEmpty())
            {
                try
                {
                    data = obj.dataR.remove();

                    data = data.replaceAll("\\s", "");

                    String[] breakout = data.split("-");
                    // all set to this point
                    if(breakout.length == 12)
                    {

                        batchNum = breakout[0];
                        fileNum = breakout[1];

                        time = breakout[2] + ":" + breakout[3] + ":" + breakout[4] + ":" + breakout[5] ;

                        if(checksum(breakout[8]))
                        {
                            temporary = (float) Integer.parseInt(breakout[8].substring(breakout[8].length()-4, breakout[8].length()-2), 16);
                            temporary = temporary * (float) .1;
                            temp = String.valueOf( temporary);
                        }
                        else
                            temp = "Chksm Err";

                        if(checksum(breakout[11]))
                        {
                            temporary = (float) Integer.parseInt(breakout[11].substring(breakout[11].length()-4, breakout[11].length()-2));
                            //temporary = temporary *
                            conc = String.valueOf(temporary);
                        }
                        else
                            conc = "Chksm Err";

                        record = new SensorRecord(batchNum, fileNum, time, temp, conc);

                        obj.db.addSensorRecord(record);

                   }
                }
                catch (NoSuchElementException e)
                {}

                obj.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run ()
                    {
         
                        obj.adapter.notifyDataSetChanged();
                    }
                });
            }// end of if
        }
    }

    private boolean checksum(String data)
    {

        int length = data.length();
        boolean ck = false;
        int checksum = 0;
        int n = 0;

        String iChksm = data.substring(data.length()-2);

        for (n = 0; n < length - 2; n++)
        {
            checksum = checksum + data.charAt(n);
        }
        checksum = 255 - checksum + 1;
        checksum = checksum + 256 + 256;

        if (Integer.parseInt(iChksm, 16) == checksum)
            ck = true;

        return ck;
    }
}

I use runOnUiThread to add new requests to the stack of UI Thread. The call I thought would work was the notifyDataSetChanged(). But it doesn't update with any of the data coming in over the wire. All I see is blank lines, hundreds of them.

I create and set the adapter in the onCreate of the activity.

All functionality of the main activity has worked thus far. But after hitting the Read Sensor button, nothing populates in the List view and then, all functionality from Sync or the settings activity fail to work.

Could someone lend some insight as to where I should be looking. I'm not getting any errors, Its hard to debug when Its not connected to Android Studio. With that being said, I have a second application that I use to test all of the data parsing and verify that the data coming in over the wire is what its suppose to be. I have tested all the calls, send/receive, parsing, and etc on this second application first.

Here is the Adapter class

Java:
package com.ascenzi.rhmps;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.List;

public class SensorFeedAdapter extends ArrayAdapter<SensorRecord>
{
    Context context;
    String aBatchNum;
    String aFileNum;
    String aTime;
    String aTemp;
    String aConc;


    public SensorFeedAdapter (Context c, List<SensorRecord> records)
    {
        super(c, 0, records);


    }


    @Override
    public View getView (int position, View convertView, ViewGroup parent)
    {

        SensorRecord record = getItem(position);

        if (convertView == null)
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.sensor_feed_item_row, parent, false);

        TextView batch =convertView.findViewById(R.id.batchTextView);
        TextView file = convertView.findViewById(R.id.fileTextView);
        TextView time = convertView.findViewById(R.id.timerTextView);
        TextView temp = convertView.findViewById(R.id.tempTextView);
        TextView conc = convertView.findViewById(R.id.concenTextView);

        batch.setText(aBatchNum);
        file.setText(aFileNum);
        time.setText(aTime);
        temp.setText(aTemp);
        conc.setText(aConc);

        return convertView;
    }
}

and here is the instantiation of the adapter class.

Java:
        adapter = new SensorFeedAdapter(this, records);
        sensorFeedList.setAdapter(adapter);

App Downloaded from Play Store Crash

I have published a simple game to learn the publishing process, Popprz, on both Apple and Google developed using Cocos2d-x.

The downloaded & installed game runs happily on some devices, Huawei P10 & Samsung Galaxy 10 for example, but crashes on a Samsung S6 & Honor 8 Pro.

When I try to debug the issue from Android Studio I find I can happily debug the same app on, for example, the Samsung S6 & Honor 8 Pro - no problems :[

Can anyone suggest how I should try and identify the problem(s)?

Thanks

SQL JSON get array instead of object

Hi.

i am using this code to get some info from a sql database.

I can't figure out how to return a array if there are more than one record with the same email.


Somehow i have to put the $stmt->fetch(); in a while function and then array_push it together i think.

in java then create a array and load it in to it.

Can someone help??


Regards Danni.


PHP:
Code:
if (!empty($_POST)) {

    $response = array("error" => FALSE);

    $query = "SELECT * FROM users WHERE email = :email";

    $query_params = array(
        ':email' => $_POST['email']
    );

    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }

    catch (PDOException $ex) {
        $response["error"] = true;
        $response["message"] = "Database Error 1";
        die(json_encode($response));
    }

    $validated_info = false;
    $email = $_POST['email'];

    $row = $stmt->fetch();

        $response["error"] = false;
        $response["user"]["uid"] = $row["unique_id"];
        $response["user"]["name"] = $row["name"];
        $response["user"]["email"] = $row["email"];

        die(json_encode($response));

}

JAVA:
Code:
StringRequest strReq = new StringRequest(Request.Method.POST,
                Functions.LOGIN_URL, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Login Response: " + response);
                hideDialog();

                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");

                    // Check for error node in json
                    if (!error) {
                        // user successfully logged in
                        JSONObject json_user = jObj.getJSONObject("user");

                    } 
                } catch (JSONException e) {
                    // JSON error
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }, new Response.ErrorListener() {

        }) {

            @Override
            protected Map<String, String> getParams() {
                // Posting parameters to php
                Map<String, String> params = new HashMap<String, String>();
                params.put("email", email);

                return params;
            }

        };

System doesn't unmute notifications

When I mute using the hot key in the tray, all options go to mute. However, when I deselect same button and return soind, media & calls return to same level as before however the notifications option stays mutted. It didn't always do this but it's been going on for at least a few months. I'm up to date on system updates. Android 9 Kernal 4.4.153 July 31.

Any known fixes?

Tech Dummie 101 help

I recently had the pie 9 update on phone which by the way I could hardly work it for a month. I'm that person that loves changing the back and the key Board
..
But oviously not good download this down....not good...I know something or someone is on my phone now but it looks like there protect it..Amways 1st time need navigation and def the best themes having nova launcher

big problem with internet connection

Hi all.
I have a big problem with my internet connection when I am using Wifi at my home.
The thing is that near my home there are some restaurants that have conections that appears to be free but aren't free.
The problem is that even when I click on my home network to connect it connects fine but 5 minutes later Android decides that it wants to connect to the open networks nearby that are not really open and interupts my connection.
I trried installing Wifi MAnager but that didn't help.
Do anyone know of an app or patch that will make my mobile connect to the network that I WANT TO CONNECT TO and not forcing me to connect to other networks that aren't mine.
It's a. shame the computer world these days I mean I had a Windows xp Computer that would let me choose MY NETWORK and it STAYED CONNECTED TO MY NETWORK.
And then there is this peace of crap of os that is of 2016 that won't connect to my Wifi because it's so stupidly made that it decides where to connect.
I have to find a way to stop android from searching and connecting to a network AFTER I SELECT MY HOME NETWORK SO IT WILL STAY CONNECTED TO MY NETWORK.
I tried that in Wifi manager but it doesn't stop android from searching and connecting to other networks even when I turn Auto Search off in Wifi manager and Android settings don't even have that option.
Please help me because it is a very expensive high end phone and if I don't find a solution for this I might sell everyrhing and stop using computers and phones altogether.
I am so fed up of this modern computer world that is more terrible then the 90's
Windows 95 was WAY BETTER then all this crap

Apps Is there possibility to "Auto-start" application when users become inactive?

Hi,
I have to create an app, which detects user inactivity, and then start activity which displays some videos with WebView, and then when displaying with WebView is finished, it has to play videos from SDCard. I've already handled part with WebView and SDCard (with JavaScriptInterface etc.)
This application has to work with API 19 all the way to the newest one.

The question is - Is there a possibility to detect if user is inactive and start my application, or keep the app running in background, and then start activity in the foreground after the user becomes inactive for certain time?

I'm not trying to play ads, when user is not looking at his screen. Application is for my client, who have stores with all kind of electrical equipments, including smartphones. The goal is to play video presentations with hardware details specific for each smartphone (informations about processor, ram, camera, screen etc.).

In short: I have to make an app which is similar to "Demo Apps" created for example by Samsung (playing some kind of presentations on screen).

So far I've read and tested things like:

1) BroadcastReceiver with combination of ACTION_SCREEN_OFF / ACTION_SCREEN_ON events.

Receiver works properly, I can detect this event and then start activity, but... The screen is already off so i can't see the displayed activity - it's visible running in the foreground after unlocking the phone. Is there a way to unlock the phone when the event is received?

That's my code so far.
EventReceiver Class:
Code:
class EventReceiver: BroadcastReceiver() {
   override fun onReceive(context: Context, intent: Intent) {
       StringBuilder().apply {
           append("Action: ${intent.action}\n")
           append("URI: ${intent.toUri(Intent.URI_INTENT_SCHEME)}\n")
           toString().also { log ->
               Log.d(TAG, log)
               Toast.makeText(context, log, Toast.LENGTH_LONG).show()
           }
       }

       if (intent.action == Intent.ACTION_SCREEN_OFF) {
           val i = Intent(context, MainActivity::class.java)
           context.startActivity(i)
       }
   }
}

MainActivity Class:
Code:
val br : BroadcastReceiver = EventReceiver()
val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION).apply {
   addAction(Intent.ACTION_SCREEN_OFF)
   addAction(Intent.ACTION_SCREEN_ON)
   addAction(Intent.ACTION_BOOT_COMPLETED)
}

2) Foreground Services - I read that this is a great way to make some asyc stuff in the background and show notifications to user. Is there a way to start the activity with it?

3) Job Scheduler

4) Daydream / Dream Service - it actually works great with almost every API and manufacturer, but.. there's no way to set the app as Screen Saver on Huawei/Honor smartphones, at least from phone settings, I've read that this is possible with ADB etc. but this is not an option that I can use here.

It seems that none of these fullfill my expectations.

X23. Great phone but is also fraud.

Wish.com has X23 as a phone you can buy.
Advertised as...
6.3 inch screen
6 GB RAM
128 GB ROM
Android 9.1
10 core.
6000 mAh
For about $100 USD.
It's got code in it to make that seem true. However, upon use you realize that it's a lie.
Actual specs.
2 GB RAM
32GB ROM
Android 6.0
4 core.
??? mAH. Estimate is 3200 based on a battery app.
Use 3rd party apps to see the real specs. Disk space was the hardest to figure out after consuming about 26gb, it will suddenly say you're almost out of space (128gb). For example.
However, this phone is very quick and the battery lasts about 8hrs of constant use. Longer if it's screen is off most of the day.
2 rear cameras exist but no knowledge of how to use the 2nd rear one exists. 3rd party apps don't seem to let you use it either. This night just be that I need to write a new camera app myself to access it.

Attachments

  • Screenshot_20190914-205442.png
    Screenshot_20190914-205442.png
    105.4 KB · Views: 153
  • Screenshot_20190905-140552.png
    Screenshot_20190905-140552.png
    189.7 KB · Views: 155
  • Screenshot_20190905-140534.png
    Screenshot_20190905-140534.png
    157.6 KB · Views: 144

Micro Launcher

I'm writing a new launcher. The smallest in size, memory use and quickest speed and navigation possible. Multiprocessor use everywhere possible. Completely different than other launchers. Here is an Alpha stage screenshot.

Attachments

  • Screenshot_20190908-174649.png
    Screenshot_20190908-174649.png
    144.9 KB · Views: 195

android tablet question

can a android tablet that has the hdmi port receive video from that port from another device?

i have a dvr and an nvr and i have them connected to a monitor now thru a vga cable and both units have an hdmi port. what i want to do is connect an hdmi cable to one of them and hook it up to a tablet in another room and seed the feed from those recorders. my tablet has a mini hdmi port on it now. what i need find out is if tables can receive feed from another device. thanks

Can't mute notifications

Hello. I'm hoping someone can help me. I have an app that notifies me throughout the day when it's time to take my meds/vitamins. I set it up so that I can get the pop-up without any sound (it's disruptive when I'm at work). Since the evening of Thursday, September 12th, the app has been making a sound when the notification pops up. I've tried everything I can think of to stop it: checked the app's settings, silenced the notifications volume, I even checked for app and phone updates. The only thing that works is when I put the media on mute. It's annoying and frustrating. Any ideas on how to fix this?

Filter

Back
Top Bottom