I'm developing an Android app to interface with a custom accessory, using a Moto X 1st-gen and a Galaxy S5 for testing. On both of these phones, when the accessory is connected, instead of prompting the user to launch the app, it simply displays a gray modal with the accessory company's logo. The strange thing is that if I have multiple apps installed with this accessory filter, the launch-app prompt does pop up, and if I select my app and launch it through the prompt, it works as expected. If I select 'always launch' and then uninstall the other app, it works as expected. But if I update the app, the problem resurfaces.
I can't seem to find any other instances of this problem occurring. I've tried changing which Activity the intent-filter is tied to; no luck.
I've configured the AndroidManifest like so:
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.usb.accessory" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
...
<activity
android:name=".activity.AccessoryActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
</application>
And have my accessory_filter set up like so:
<resources>
<usb-accessory manufacturer="My-Manufacturer" model="My-Model" version="1.0"/>
</resources>
It seems that this behavior was occurring because I was using a large PNG (671x725) in the drawable folder as the app icon. When I got around to creating individual icons at the appropriate dpi sizes, the problem vanished. I have no clue why icon size would have any bearing whatsoever on the ability of the OS to launch an app on accessory connect, but there you go.
Related
I am working on an AAOS (Android Automotive OS) platform. The OS version is 10.
I included "DirectRenderingCluster" in my car_product/build/car.mk as
PRODUCT_PACKAGES += DirectRenderingCluster.
In this App, there is a ClusterRenderingService, which implements InstrumentClusterRenderingService.
In InstrumentClusterRenderingService, it will try to gather some information of the suitable navigation App from the PackageManager. Originally, it will pick the FakeClusterNavigationActivity in EmbeddedKitchenSinkApp.
I want to replace the FakeClusterNavigationActivity with my own navigation App.
I mimicked it and made a similar activity.
However, I am getting error messages printed at line 153 and 299 of InstrumentClusterRenderingService.
What do I miss? What should I do to make the Car service recognize my App is an eligible navigation App for cluster? Thank you.
My AndroidManifest.xml looks like as follows. The targetSdkVersion is 29.
<manifest
package="com.mytest.android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="1.0"
android:versionCode="1"
android:installLocation="auto"
android:sharedUserId="android.uid.system">
<application
android:hardwareAccelerated="true"
android:directBootAware="true"
android:persistent="false"
android:name="com.mytest.android.NaviApp"
android:label="#string/application_label"
android:icon="#drawable/icon">
<!-- Activity for cluster. Note that this is not the only activity in this App. -->
<activity android:process=":map_surface"
android:name=".MapSurfaceActivity"
android:label="MapSurfaceActivity"
android:screenOrientation="landscape"
android:launchMode="singleInstance"
android:allowEmbedded="true"
android:exported="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.car.cluster.NAVIGATION"/>
</intent-filter>
</activity>
<!-- Content provider for images (fake, not functional) -->
<provider android:name=".cluster.ClusterContentProvider"
android:authorities="com.mytest.android.cluster.clustercontentprovider"
android:grantUriPermissions="true"
android:exported="true"/>
It turns out to be Google's bug and has been fixed in the later code.
If the navigation app is launched as non-system user and is not installed for system user, this bug will occur.
In the original code, it uses system user's PackageManager to call getPackageInfo() and queryIntentActivities(). However, the navigation app is not installed for system user (maybe being put in the blacklist), so it won't be found.
To fix, PackageManager.MATCH_ANY_USER flag should be used in getPackageInfo(), and queryIntentActivitiesAsUser() should be used in stead of queryIntentActivities().
I don't know what commits fixed them but they are shown in the master branch.
https://android.googlesource.com/platform/packages/services/Car/+/master/car-lib/src/android/car/cluster/renderer/InstrumentClusterRenderingService.java
The problem occurred overnight. One day, everything worked fine. I shut my computer down and started it back up on another day. However, without changing a thing, I tried to launch my App on the same virtual device I had before and somehow it wont launch because:
"Error running 'app'. Default Activity not found."
My manifest looks like this. I changed the package name and the two activities below (see comments below). The rest is exactly the same.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MyPackageName">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<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=".LoginActivity"
android:label="#string/title_activity_login"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:screenOrientation="portrait">
</activity>
<activity android:name=".AnotherActivity" />
<activity android:name=".OneMoreActivity">
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="364e8b3f6acfddf9ad32bed8c1503bb762b19cd5" />
</application>
</manifest>
And normally my app would just start with the Login Activity. However, now it does not. I tried to "Invalidate Caches / Restart". Nothing changed. I restarted AS multiple times. Still, nothing.
Then I tried to change the Launch Options. Current Option was set to "Default Activity". So I tried to change it to a specific one. Namely, the LoginActivity. But then it tells me:
"Error running 'app'. The Activity 'LoginActivity' is not declared in AndroidManifest.xml."
It tells me it's not declared, which it clearly is. Otherwise I wouldn't be able to choose it from the dropdown in the first place. I also tried to start on another Activity. "MainActivity". Still nothing.
What exactly am I doing wrong? Is there maybe a workaround where I can manually get the APK on my virtual device so that I can at least keep working?
Edit
I already tried deleting the .gradle-folder. Sadly this didn't work. I tried pushing it to git and cloning it again in another folder. That didn't work either.
Workaround
So far I've only been able to find a workaround:
Go to Run/Edit Configurations...
Go to General/Launch Options -> Launch: Nothing
Run as you normally would. Android Studio will build the project and install the application to your device, but won't launch it!
Launch your app manually on your device.
Go to Run/Attach Debugger to Android Process.
Choose your app.
Obviously, that's a little bit of a hassle and might make debugging the start of an app more difficult. So I'm still looking for an actual solution.
I've found the answer when I tried to look for a solution to another problem that randomly popped up out of nowhere.
Androidstudio wouldnt load any previews and put warnings in my layouts, because
One or more layouts are missing the layout_width or layout_height attributes.
One solution suggested in
the answer I found for that problem
was to delete all files in
C:\Users\UserName.AndroidStudio3.2\system\caches
Thats what I did and it solved both problems. Guess the developers have some fixing to do.
I have spent a long time on forums looking at how to change the theme for my activities in android app development.
My main objective is to remove the title bar. But would still like to know how to change themes in general.
I have tried changing the theme using the GUI built into Android Studio... the theme changes in the preview, but when I run the app on my phone nothing changes.
So I figured I would change the theme using some xml code in the Manifest file.
What everyone seems to be doing is the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dennis.activeapp" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
<!-- HERE IS WHERE I SET THE THEME -->
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecActivity"
android:label="#string/title_activity_sec" >
</activity>
<activity
android:name=".FirActivity"
android:label="#string/title_activity_fir" >
</activity>
</application>
</manifest>
The above is my code.
Now, when I try to run this on my phone the app crashes. The app opens for a fraction of a second and then closes.
If it is any help my phone is the Cubot S208. Since I have a feeling the problem might not be the code, as I followed directly what people have said in previous posts/forums.
The error message I receive in the ADB logs is the following:
ddms: null
java.lang.NullPointerException
at com.android.ddmlib.Client.read(Client.java:731)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:311)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
PropertyFetcher: AdbCommandRejectedException getting properties for device 0123456789ABCDEF: device unauthorized. Please check the confirmation dialog on your device.
PropertyFetcher: AdbCommandRejectedException getting properties for device 0123456789ABCDEF: device unauthorized. Please check the confirmation dialog on your device.
However I am certain that is the code below the comment (The theme) that is causing this issue. As without it I have no crash !
When i download my app from store.
its installed on main screen, and on apps menu ( when i click the circle with 6 dots on it )
when i click from main screen it opens an app, and when i click from the other place..it opens a second app as well.
i need one app running only..
how can this be fixed?
my manifest
<application
android:name="dfsfsdp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartupActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I think you aren't running multiples instances (if you are running multiple instances if fail of the mobile), or you see two applications open in the menu what you use to close the running apps (the recent applications menu)?
If you only see one maybe your are restarting the same instance. Look at your StartupActivity or post here to try help you.
If this don't help you, take a look at to read about the lifecycle of an Activity:
http://developer.android.com/training/basics/activity-lifecycle/index.html
Best regards.
i'm deploying an android application (Android 4.0.3) and when I press the home screen the application doesn't stay on the recent apps list. I've noticed that when I restart the application, it starts on the last screen i've navigated before press the home button. Anyone can help? Here is me Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/logo_home"
android:allowBackup="true">
<activity
android:name="com.test.activity.CommunicatorActivity"
android:launchMode="singleTop"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.test.activity.InputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.SettingsActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
<activity android:name="com.test.activity.OutputActivity"
android:windowSoftInputMode="adjustPan|stateHidden">
</activity>
</application>
</manifest>
I'm going to go out on a limb and suggest that this is your problem:
android:label=""
In your root activity CommunicatorActivity you've set the label to be an empty string. This label is used to identify your app in the list of available apps and because it is empty, this may be causing it not to show up in the list of recent apps.
Remove android:excludeFromRecents="true" from your manifest
You should use
android:label="your app_name"
2 things
Ok, there isn't something obvious in your manifest that should prevent it from appearing in your recents list.
1. Wrong identification
It's not always straight forward to tell which task contains your activity, using the GUI.
One of the possibilities is that an activity from some other app is on top of your task making you believe that your activity isn't there. Since, clearly it resumes to the last screen.
I suggest you to remove the single top temporarily and check the same.
2. Launcher modification
Has the launcher you use the standard launcher? Has the launcher or some other app modified the presentation or behavior of the recents screen (unlikely but worth a check)
For this, I suggest using a stock launcher or try the same app on a different phone or an emulator.
What would help is steps you followed and some screen shots of recents
screen and also of your app
I had the same problem.
The reason is that I had set android:label="" in manifest.xml.
I hadn't set android:launchMode="singleTop".
I declared on purpose android:label="" because I didn't find any better way to remove the title of the action bar from my main activity.
I turned android:label="app_name" again and everything now is OK; the app appears again in recent app list when pressing the home screen and doesn't start on the last navigated screen when restarting it.