I am working on an app and I am trying to find a way to wake the screen when I plug a usb camera to the phone while screen off on a android phone. I tried to monitor my usb connection but it didn't work, once the screen off, my app can no longer tell if a usb camera is connected.
Can somebody give me some ideas about how to do that? Thanks!
First: U need start the app when usb camera inserted
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter"/>
</activity>
Second: keep screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
That work for me!
Related
So there is an activity containing a webview. On launch/click on App Icon it should launch activity with webview as dialog on the HomeScreen of the device.
Is there a way to achieve this?
Yes, you can do it. Set the theme of MainActivity to Dialog, then you'll achieve it.
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It works fine for me. Hope it can help you~
I am trying to stop the app I am working on from asking for USB permissions each time the USB device is disconnected. I have followed: USB device access pop-up suppression? without much luck.
The app does remember the USB device until the device is unplugged.
If it matters I am trying to connect the app to an Arduino Teensy.
This is what my manifest activity looks like
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <!-- For receiving data from another application -->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="#xml/usb_device_filter" />
</activity>
</application>
And here is my usb_device_filter file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="--hidden--" product-id="--hidden--" />
</resources>
Any help is welcome.
EDIT: I also look over at the Android Developer page and they say when using an intent filter for USB connections: If users accept, your application automatically has permission to access the device until the device is disconnected.
I would also like to point out that the suggested duplicate does not have the same issue as I am trying to solve. Their problem is having two activities while my problem deals with just one.
https://developer.android.com/guide/topics/connectivity/usb/host
We ended up opening the app automatically when the USB is inserted into the phone, because our project deals with the app being open all day.
The app only asks for permission to use the USB once for the phone and remembers it now, as long as the user connects the USB before opening the app and the phone is unlocked. The phone even remembers the permission after the phone is restarted.
This is kind of a work around, but it works for our needs. Hopefully this will help some others with the same problem.
As the asker here says, For your perpose (if I understood correctly) the following should be enough. That's right that he had a different problem but he started hes question saying that for your case it's working.
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/usb_device_filter" />
</activity>
I am trying to show user my settings application. To do that, user must select application in Preference Dialog. I have been successful until i install my app into a 6.0.1 version. It used to work well with 4.4.2 version.
<activity android:name=".ui.activity.SettingsActivity">
<intent-filter>
<action android:name="android.settings.SETTINGS"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This code is I used before, I changed it like this but result is the same
<activity android:name=".ui.activity.SettingsActivity">
<intent-filter>
<action android:name="android.settings.SETTINGS"></action>
<action android:name="android.settings.DISPLAY_SETTINGS"></action>
<action android:name="android.settings.HOME_SETTINGS"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Can anyone help me with which action should I use or is it blocked by Android System after 6.0.1 devices?
I am developing Android Wallet application using SEEK API and NFC. I have the Visa applet installed in the Sim card. My question is, How to detect if a successful/unsuccessful contact is made to the POS terminal? Is there any Intent Action available in Android that I can put in some activity or some receiver?
Thanks.
Actually I Found the way of detecting POS terminal transaction. The NFC API, TRANSACTION_DETECTED is hidden. When transaction is there, TagDetectedActivity will launch.
<activity android:name=".TagDetectedActivity" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.nfc.action.TRANSACTION_DETECTED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="nfc" android:host="secure" android:port="0" android:pathPrefix="/axxxxx" />
</intent-filter>
<intent-filter>
<action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="nfc" android:host="secure" android:port="0" android:pathPattern="/.*/axxxxx.*" />
</intent-filter>
</activity>
I'm a newbie programming for android, I made a simple game some days ago and I tried to install it in a tablet(Android 4.0).
The program works ok, but I got four(4) icons of my app after installation and only one of them is correct(third).
I just want to know how I can to solve this bug so that when I install it in another device it runs ok and get only one icon.
Thanks in advance.
It's because in your manifest you need to change all of your activities EXCEPT your first activity (usually your mainActivity) from:
<activity
android:name=".SecondActivity"
android:label="activity name" >
<intent-filter
android:label="Your App Name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
to:
<activity
android:name=".SecondActivity"
android:label="activity name" >
</activity>
Basically just take the intent-filter out of all your activities that are NOT your main activity. Your main activity needs it so that there is a launcher icon. Hope that helps.
I got four(4) icons of my app after installation
means you have declared more then one Activity in AndroidManifest.xml as launch Activity. to show only one Activity as launcher you will need to declare only one Activity with android.intent.action.MAIN and android.intent.category.LAUNCHER intent-filter.
Declare Main Activity which u want to show in Launcher as:
<activity android:name="MainActvity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and other 3 Activity declare as in AndroidManifest.xml as :
<activity android:name="Actvity_Two"
android:label="#string/app_name" />
<activity android:name="Actvity_Three"
android:label="#string/app_name" />
//declare other in same way ..