I an currently working on an intensive LiveWallpaper that draws to the canvas. I happened upon the following video: http://www.youtube.com/watch?v=v9S5EO7CLjo.
However when I tried to implement hardware acceleration, I get errors. Here is my code:
if (c != null && mStaticRects.length > 10 && c.isHardwareAccelerated())
drawSurfacePortrait(c);
if (c != null && mStaticRects.length < 20 && c.isHardwareAccelerated())
drawSurfaceLandscape(c);
When I run this, here is the corresponding error:
AndroidRuntime(382): java.lang.NoSuchMethodError: android.graphics.Canvas.isHardwareAccelerated
and finally here is my Manifest...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="stuff.of.mine"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
***android:hardwareAccelerated="true"***>
<service
android:name=".SomeWPService"
android:permission="android.permission.BIND_WALLPAPER"
***android:hardwareAccelerated="true"***>
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/mylwp" />
</service>
</application>
Ok, I was searching around stackoverflow and stumbled upon the answer to my own question
In fact, Romain Guy, one of the guys in the video answered on the following thread:
Canvas in SurfaceView - hardware acceleration
He says:
A Canvas returned by SurfaceView.lockCanvas() cannot be hardware accelerated at the moment.
What I want to know is how you can create a live wallpaper without SurfaceView.lock and unlockCanvas?
canvas.isHardwareAcceleratedis introduced in API 11 and your minSdkVersion is 7. Try changing that to 11.
You can control hardware acceleration at the following levels:
Application
Activity
Window
View
in your code,
<service
android:name=".SomeWPService"
android:permission="android.permission.BIND_WALLPAPER"
***android:hardwareAccelerated="true"***>
service tag doesn't contain android:hardwareAccelerated !
Related
I have an Android mobile app and now I'm trying to run it on Android TV emulator, but it doesn't respond to screen orientation, it is always in portrait mode even though I handled it in code (it0s working both on mobile and tablet).. This is my AndroidManifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="------">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="android.permission.REBOOT" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:name="-----"
android:allowBackup="true"
android:icon="#drawable/ic_launcher_2"
android:label="#string/app_nameMain"
android:launchMode="singleTask"
android:theme="#style/AppTheme"
tools:replace="android:label">
<activity
android:name=".activities.LauncherActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:theme="#style/App.Theme.Translucent"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.LogInActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".activities.BrowserManagerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/MyHomeCustomTheme"
android:windowSoftInputMode="adjustPan" />
</application>
I also tried adding this line of code but it's not helping:
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
Did you have similar experience or do you have any ideas what's the problem here?
I think it is not about your application orientation configurations. Many Android-tv producers force the orientation as landscape. If you have access, you may check system properties and find about x.forceorientation:landscape and change it.
Some producers have also put a settings menu option such as System Settings > Display > Rotate.
Another way, this application can work on some devices
I had the same problem but with a real TV device - the system ignored rotation at all (everything worked fine on tablets and phones).
I found solution for my case but it can be inappropriate for you.
So, the short answer is "impossible" the long answer goes here:
Firmware for TV devices often tweaked by their manufacturers, in my case it was /system/framework/services.jar
that contained services\com\android\server\wm\WindowManagerService.java
in which the following code handled the rotation case:
if ("box".equals(SystemProperties.get("ro.target.product", "tablet"))) {
rotation = 0;
}
of course the /system/build.prop has setting ro.target.product=box, when I tried to patch this file (I had root and possibility to reflash firmware) the system went into the kind of boot loop. The parameter ro.target.product was used several times inside system applications so I think that final firmware in my case lacks some additional code to handle other target modes. Because of this I was forced to patch classes.dex directly in order to turn this checking off.
Another set of options that controls rotation are persist.demo.hdmirotates and persist.demo.hdmirotation, by default they were turned off. When I added them via the command line:
setprop persist.demo.hdmirotates true
setprop persist.demo.hdmirotation landscape
I got desired behavior: my application chooses necessary orientation and it works! In my case the rotation of TV depends upon cabling requirements, i.e. the relative position of TV and its corresponding socket outlet on the wall.
So, no free lunch :-( each device should be handled separately.
I am trying to create a very simple QR input method in Android. Far from being actually runnable in "production", I am trying to run my custom QR keyboard application on my Nexus 6 device, at least to see where it will crash.
However, after deploying the APK to the device I cannot choose my custom input.
Following is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.zighinetto.qrkey" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<service
android:name=".services.QrInputService"
android:enabled="true"
android:permission="android.permissions.BIND_INPUT_METHOD" >
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="#xml/ime" />
</service>
<activity
android:name=".ui.SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
</application>
</manifest>
And... ime.xml
<?xml version="1.0" encoding="utf-8"?>
<input-method
android:isDefault="true"
xmlns:android="http://schemas.android.com/apk/res/android">
</input-method>
So far I have:
- Enabled CAMERA permission because I need to use the camera
- Created the IME service and linked it to the BIND_INPUT_METHOD permission, so that only the system can bind to it
- NOT declared the BIND_INPUT_METHOD as permission used by my application, because only the system needs that permission.
I expect the new QR input service to be visible in Android's "Language and input" screen, however I cannot see it.
What is wrong in my manifest?
I have a weird problem. I set the screen orientation in android manifest and it works on emulater but not on the actual device. I also changed the orientation programmatically and still the problem persists. My manifest is as follows -
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.rotatedsignage"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.rotatedsignage.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.rotatedsignage.BootReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
What is wrong with my code? The code I used -
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
any help is appreciated. Thanks in advance.
Check in your device under Settings section that whether your AutoRotate screen is locked or not.If it is locked then uncheck it.
Hope this helps.
First check your device settings as Siddharth Vyas suggest you, then make some changes like following in your config file.
<preference name="orientation" value="default" />
default means both landscape and portrait are enabled or else you can put portrait and landscape whatever you want in place of default. Hope this helps.
I restarted the app in my android phone and screen rotation started to work. I think, for a real device, if changes are made in app.json, then app needs to be restarted to see the changes.
I have a basic clock widget here, it works just fine on versions of android below 4.0, you can long press, select widgets and its right there. But when i try to run it on 4.0 or later emulator or real device, it does not show up in widgets section only in Settings>Storage>Apps. I have tried adding a simple activity that just gives users directions on how to install the widget , that suggestion was given as an answer here: Android 4.0: widgets not appearing? . Unless i did it wrong the widget still does not show up in widget drawer.
Here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.widgetexample1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<receiver android:name=".ExampleAppWidgetProvider"
android:label="8-bit cloud widget 1">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget1_info" />
</receiver>
</application>
</manifest>
add below in your manifest.xml.
"android:exported="true".
it might help.
try it.
In your widget metadata xml file check tag <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:xmlns attribute should start with http://.
It looks like you are being hit by a security upgrade which I think happened in HoneyComb.
Basically, in newer versions of Android, you cannot have your widget working, without first launching an Activity.
So add an activity to the project, run it first, and I think your widgets will update.
A good example would be to use a Settings style activity, or perhaps and About box type of thing, to tell the user a bit about your widget. (I use settings in my widgets).
For more info:
Android 4.0: widgets not appearing?
my android application performance is low, it takes a long startup time. i have 5 buttons, one imageview, 3 textView, 2 editText and one listView initialized in onCreate() method. Is large number of ui object the reason for slow startup?? Is there any fault in manifest.xml??
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ars.application"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/lightvasicon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".LightVas"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission
android:name="android.permission.CONTROL_LOCATION_UPDATES"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="7" />
</manifest>
Generic performance advice:
In most cases you shouldn't try to guess what is causing performance problems as intuition is often wrong. If you knew the cause of slow code, you wouldn't have written it slow in the first place!
Use the profiler to work out where your performance problems are.
Optimize just the slow parts. Keep a copy of your traces and compare them after making a change, so you know whether you're heading in the right direction or not.
Make your own simple timing method to verify your results, this will make sure that trace recording itself is not causing performance issues in a different place.