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

Help How can I show the time in big numbers while logged-in?

Wait! I got the forum's search feature to work, and I found the answer. You can display the time using a "widget": https://androidforums.com/threads/clock-clock.1119127/

-TC

On Motorola phones that is called the "Time and Weather" widget. Just long-press on the Home screen and scroll down till you see "Time and Weather", then drag it to your home screen.

Android Auto

Im not sure what else would need blue tooth in his case.

You can disable this app. Swipe down, settings, apps&notifications, see all apps, Android Auto

Or there is the "Driving Mode" setting

To set it up on the Pixel 3:

  1. Open the Settings app.
  2. Tap Connected devices > Connection preferences > Driving mode.
  3. Tap Behavior. Choose 'Open Android Auto' or 'Turn on Do Not Disturb'
  4. Tap Turn on Automatically. Choose how you would like your phone to detect driving.

Passing an object of a Usb Service to another activity

Hello,
I'm new to Android development and I'm attempting to pass an object of a USB service from one activity to another.

I've attempted to do it two ways thus far. Implementing Parcelable and Implementing Serializable. Both means cause the system to throw and exception. In regards to Serializable, it threw an IOException.

Here is the code for my USBService, care of Felhr85.

Code:
package com.ascenzi.usb_serial_testing;

import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.widget.TextView;

import com.felhr.usbserial.CDCSerialDevice;
import com.felhr.usbserial.UsbSerialDevice;
import com.felhr.usbserial.UsbSerialInterface;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;

import java.util.HashMap;
import java.util.Map;

//import okio.Buffer;

public class UsbService extends Service implements Serializable
{

    public static final String TAG = "UsbService";

    public static final String ACTION_USB_READY = "com.felhr.connectivityservices.USB_READY";
    public static final String ACTION_USB_ATTACHED = "android.hardware.usb.action.USB_DEVICE_ATTACHED";
    public static final String ACTION_USB_DETACHED = "android.hardware.usb.action.USB_DEVICE_DETACHED";
    public static final String ACTION_USB_NOT_SUPPORTED = "com.felhr.usbservice.USB_NOT_SUPPORTED";
    public static final String ACTION_NO_USB = "com.felhr.usbservice.NO_USB";
    public static final String ACTION_USB_PERMISSION_GRANTED = "com.felhr.usbservice.USB_PERMISSION_GRANTED";
    public static final String ACTION_USB_PERMISSION_NOT_GRANTED = "com.felhr.usbservice.USB_PERMISSION_NOT_GRANTED";
    public static final String ACTION_USB_DISCONNECTED = "com.felhr.usbservice.USB_DISCONNECTED";
    public static final String ACTION_CDC_DRIVER_NOT_WORKING = "com.felhr.connectivityservices.ACTION_CDC_DRIVER_NOT_WORKING";
    public static final String ACTION_USB_DEVICE_NOT_WORKING = "com.felhr.connectivityservices.ACTION_USB_DEVICE_NOT_WORKING";
    public static final int MESSAGE_FROM_SERIAL_PORT = 0;
    public static final int CTS_CHANGE = 1;
    public static final int DSR_CHANGE = 2;
    private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
    private static final int BAUD_RATE = 115200; // BaudRate. Change this value if you need
    public static boolean SERVICE_CONNECTED = false;

    private IBinder binder = new UsbBinder();

    private Context context;
    private Handler mHandler;
    private UsbManager usbManager;
    private UsbDevice device;
    private UsbDeviceConnection connection;
    private UsbSerialDevice serialPort;

    private TextView t1;

    //private Buffer buffer = new Buffer();
    private String mode;

    private boolean serialPortConnected;

    /*
     *  Data received from serial port will be received here. Just populate onReceivedData with your code
     *  In this particular example. byte stream is converted to String and send to UI thread to
     *  be treated there.
     */
    private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {
        @Override
        public void onReceivedData(byte[] arg0) {
            try {
                String data = new String(arg0, "UTF-8");
                if (mHandler != null)
                    mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, data).sendToTarget();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    };

    /*
     * State changes in the CTS line will be received here
     */
    private UsbSerialInterface.UsbCTSCallback ctsCallback = new UsbSerialInterface.UsbCTSCallback() {
        @Override
        public void onCTSChanged(boolean state) {
            if(mHandler != null)
                mHandler.obtainMessage(CTS_CHANGE).sendToTarget();
        }
    };

    /*
     * State changes in the DSR line will be received here
     */
    private UsbSerialInterface.UsbDSRCallback dsrCallback = new UsbSerialInterface.UsbDSRCallback() {
        @Override
        public void onDSRChanged(boolean state) {
            if(mHandler != null)
                mHandler.obtainMessage(DSR_CHANGE).sendToTarget();
        }
    };
    /*
     * Different notifications from OS will be received here (USB attached, detached, permission responses...)
     * About BroadcastReceiver: http://developer.android.com/reference/android/content/BroadcastReceiver.html
     */
    private final BroadcastReceiver usbReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            if (arg1.getAction().equals(ACTION_USB_PERMISSION)) {
                boolean granted = arg1.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
                if (granted) // User accepted our USB connection. Try to open the device as a serial port
                {
                    Intent intent = new Intent(ACTION_USB_PERMISSION_GRANTED);
                    arg0.sendBroadcast(intent);
                    connection = usbManager.openDevice(device);
                    new ConnectionThread().start();
                } else // User not accepted our USB connection. Send an Intent to the Main Activity
                {
                    Intent intent = new Intent(ACTION_USB_PERMISSION_NOT_GRANTED);
                    arg0.sendBroadcast(intent);
                }
            } else if (arg1.getAction().equals(ACTION_USB_ATTACHED)) {
                if (!serialPortConnected)
                    findSerialPortDevice(); // A USB device has been attached. Try to open it as a Serial port
            } else if (arg1.getAction().equals(ACTION_USB_DETACHED)) {
                // Usb device was disconnected. send an intent to the Main Activity
                Intent intent = new Intent(ACTION_USB_DISCONNECTED);
                arg0.sendBroadcast(intent);
                if (serialPortConnected) {
                    serialPort.close();
                }
                serialPortConnected = false;
            }
        }
    };

    /*
     * onCreate will be executed when service is started. It configures an IntentFilter to listen for
     * incoming Intents (USB ATTACHED, USB DETACHED...) and it tries to open a serial port.
     */
    @Override
    public void onCreate() {
        this.context = this;
        serialPortConnected = false;
        UsbService.SERVICE_CONNECTED = true;
        setFilter();
        usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
        findSerialPortDevice();
    }

    /* MUST READ about services
     * http://developer.android.com/guide/components/services.html
     * http://developer.android.com/guide/components/bound-services.html
     */
    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return Service.START_NOT_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        serialPort.close();
        unregisterReceiver(usbReceiver);
        UsbService.SERVICE_CONNECTED = false;
    }

    /*
     * This function will be called from MainActivity to write data through Serial Port
     */
    public void write(byte[] data) {
        if (serialPort != null)
        {
            serialPort.write(data);
        }
    }


    public void setHandler(Handler mHandler) {
        this.mHandler = mHandler;
    }

    private void findSerialPortDevice() {
        // This snippet will try to open the first encountered usb device connected, excluding usb root hubs
        HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
        if (!usbDevices.isEmpty()) {

            // first, dump the hashmap for diagnostic purposes
            for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
                device = entry.getValue();
                Log.d(TAG, String.format("USBDevice.HashMap (vid:pid) (%X:%X)-%b class:%X:%X name:%s",
                                         device.getVendorId(), device.getProductId(),
                                         UsbSerialDevice.isSupported(device),
                                         device.getDeviceClass(), device.getDeviceSubclass(),
                                         device.getDeviceName()));
            }

            for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
                device = entry.getValue();
                int deviceVID = device.getVendorId();
                int devicePID = device.getProductId();

//                if (deviceVID != 0x1d6b && (devicePID != 0x0001 && devicePID != 0x0002 && devicePID != 0x0003) && deviceVID != 0x5c6 && devicePID != 0x904c) {
                if (UsbSerialDevice.isSupported(device)) {
                    // There is a supported device connected - request permission to access it.
                    requestUserPermission();
                    break;
                } else {
                    connection = null;
                    device = null;
                }
            }
            if (device==null) {
                // There are no USB devices connected (but usb host were listed). Send an intent to MainActivity.
                Intent intent = new Intent(ACTION_NO_USB);
                sendBroadcast(intent);
            }
        } else {
            Log.d(TAG, "findSerialPortDevice() usbManager returned empty device list." );
            // There is no USB devices connected. Send an intent to MainActivity
            Intent intent = new Intent(ACTION_NO_USB);
            sendBroadcast(intent);
        }
    }

    private void setFilter() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_USB_PERMISSION);
        filter.addAction(ACTION_USB_DETACHED);
        filter.addAction(ACTION_USB_ATTACHED);
        registerReceiver(usbReceiver, filter);
    }

    /*
     * Request user permission. The response will be received in the BroadcastReceiver
     */
    private void requestUserPermission() {
        Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) );
        PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
        usbManager.requestPermission(device, mPendingIntent);
    }

    public class UsbBinder extends Binder {
        public UsbService getService() {
            return UsbService.this;
        }
    }

    /*
     * A simple thread to open a serial port.
     * Although it should be a fast operation. moving usb operations away from UI thread is a good thing.
     */
    private class ConnectionThread extends Thread {
        @Override
        public void run() {
            serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
            if (serialPort != null) {
                if (serialPort.open()) {
                    serialPortConnected = true;
                    serialPort.setBaudRate(BAUD_RATE);
                    serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
                    serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
                    serialPort.setParity(UsbSerialInterface.PARITY_NONE);
                    /**
                     * Current flow control Options:
                     * UsbSerialInterface.FLOW_CONTROL_OFF
                     * UsbSerialInterface.FLOW_CONTROL_RTS_CTS only for CP2102 and FT232
                     * UsbSerialInterface.FLOW_CONTROL_DSR_DTR only for CP2102 and FT232
                     */
                    serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
                    serialPort.read(mCallback);
                    serialPort.getCTS(ctsCallback);
                    serialPort.getDSR(dsrCallback);

                    //
                    // Some Arduinos would need some sleep because firmware wait some time to know whether a new sketch is going
                    // to be uploaded or not
                    //Thread.sleep(2000); // sleep some. YMMV with different chips.

                    // Everything went as expected. Send an intent to MainActivity
                    Intent intent = new Intent(ACTION_USB_READY);
                    context.sendBroadcast(intent);
                } else {
                    // Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit
                    // Send an Intent to Main Activity
                    if (serialPort instanceof CDCSerialDevice) {
                        Intent intent = new Intent(ACTION_CDC_DRIVER_NOT_WORKING);
                        context.sendBroadcast(intent);
                    } else {
                        Intent intent = new Intent(ACTION_USB_DEVICE_NOT_WORKING);
                        context.sendBroadcast(intent);
                    }
                }
            } else {
                // No driver for given device, even generic CDC driver could not be loaded
                Intent intent = new Intent(ACTION_USB_NOT_SUPPORTED);
                context.sendBroadcast(intent);
            }
        }
    }
}

. When I attempt to pass the Object itself I do the following.

Code:
private UsbService usbService;
...
Button swchBtn = (Button) findViewById(R.id.buttonSwitch);
        swchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v)
            {

                if(usbService != null)
                {
                    Intent swIntent = new Intent(MainActivity.this, SecondActivity.class);
                    swIntent.putExtra("USBService", usbService);
                    startActivity(swIntent);
                }
            }

before I switch activities I have done a quick check to make sure that it wasn't equal to "null". I'll change it up later and say if it is equal to null then I'll jump over but I won't send a intent extra. But for now it just crashes every time.

Any insight?

Michael

Send UDP from Application

Hello ,
I'm new at android\java so be patient :)

I want to create a small application that send a udp string to my server when I press the button.
everything is working - but it doesn't seem to send
this is what I have

btnAction.setOnClickListener(new View.OnClickListener() {
@ override
public void onClick(View v) {

try {

String messageStr = "test!";
int server_port = 1111;
DatagramSocket s = new DatagramSocket();
InetAddress local = InetAddress.getByName("My.Public.Server.IP");
int msg_length = messageStr.length();
byte[] message = messageStr.getBytes();
DatagramPacket p = new DatagramPacket(message, msg_length, local,server_port);
s.send(p);
}
catch (Exception e) {

}



}
}

whant could be the reason for it?

Thanks ,

Help Getting google calendar to see hotmail calendar on 10+

That's possible: I would never have considered configuring on a PC as I don't use Outlook on a computer. Back when I last had Outlook installed on my phone there was no such option (believe me, I looked!), but that was a couple of years ago.

(My MS account primarily exists as a backup: I've had Google's subscriptions to shared (non-Google) calendars fall over a few times over the years, so like to have an alternative I can switch to by just toggling visibilities. Plus I refuse to be dependent on any individual company, so for anything important I always have alternatives in place).

Help Transferring files to and from Acer Iconia7 tablet

Hi again, if somebody is out there :rolleyes:,
Earlier I said I can access the file directory in the tablet by way of Storage/Apps/Running/File Manager/LAUNCH/usbotg-sda1/

Now, today, the File Manager step is no longer offered in this series. How can this change? But I have discovered it in the main Apps menu and I am working on discovering how to download files from the USB-OTG drive to the tablet.
This is not yet clear to me: can someone please help?

Accessibility

Hi Friends,

I am using accessibility service in my project and its working fine but some times this permission get "This service is Malfunctioning" error, at this time i am unable to get any call backs to my accessibility service.

please help me on this.

"my project"? Is this an app or something you're developing? Maybe there's a problem with your code?

Android Development questions might be better addressed here.
https://androidforums.com/forums/android-development.28/

I'm not a dev myself of course, so can't really help you. Good luck!

[ROM]-v9 GamerROM Classic Pro™ v1.03 Nexus 6P (angler) Updated: 10/15/2019

Changelog:

• Applied security patch "October 5, 2019" update.

• Updated MusicFX this adds a new equalizer application.

• Updated Android System Webview.

• Added Original Nexus 6P (angler) stock wallpaper.

• Removed LineageOS Updater and now uses Google System Updater.

• Improvements to system performance.

• Removed all apps requiring root access.

• Applied Security Patch "September 5, 2019" update.

• Updated all built-in system apps.

• Removed Google Opinion Rewards.

• Removed GR TV (is no longer supported and you can purchase GR TV from our website for only $4.99+tax USD.

• Improved system performance and stability.

• Replaced Google Gallery Go with LineageOS Gallery.

• Added Google Play Services AR.

• Replaced ASOP Gallery with Google Gallery Go.

• Applied vendor security patch date to the build prop

• Initial release.

MAC SPOOFING

your phone number is what's used by WhatsApp
I personally know of an exception. When I originally attempted to set up WhatsApp, because my phone did not get a signal in my house, I couldn't use its number to receive the verification code. I used my landline's number, and received the code by voice.

(This led to a bewildering problem later, when I got a new phone, but that's a WHOLE other story!)

Help Moving files from old phone to new G9+

Just use Samsung's Smart Switch utility to migrate your data from your old S5 to your new S9+. It's less of a hassle transferring things manually.
https://www.sammobile.com/samsung-smart-switch/
https://www.androidcentral.com/how-use-samsung-smart-switch
You can do this by installing Smart Switch on a computer -- S5 to computer then computer to S9+; or just use the Smart Switch app installed on both phones and do the transfer via Samsung's integral S Beam technology -- S5 to S9+. I'd recommend using a computer, that way you have a full back up of your data. Backups are important, if some of your files only exist on your S5 it's really important to get a backup solution set up.
Be sure to check your S9+ thoroughly to ensure everything you need has been copied over, and don't expect perfection. You might still need to copy some things over yourself. And there could be issues with things like app data, depending on the spread between the Android operating system spread between your two phones.

Help Is there a way to permanently block an app from asking for draw over permission?

"Draw over other apps" is not one of the permissions that Google offer individual control over even in Android 10, so if it won't accept "no" for an answer all I can suggest is finding a different keyboard.

(My wife's phone came with Touchpal, and she's generally not that particular about things like that, but a few months ago even she got fed up enough with it to replace it. It's been getting worse for years, and if this particular straw isn't the breaking point all of the evidence suggests that they'll come up with something else soon).

Filter

Back
Top Bottom