Widgets not showing in Android 4.0+ - android

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?

Related

Set Android phone for ShowRoom

We, my company, are facing a problem. We have a phone in public use where we can't be always near the phone. It's a show room where public user can test our Android app.
The problem is :
1) Can we block the phone in our app ? we just pin it but it doesn't block the phone. We found some apps the make something like that but not good results
2) A test user just add a security password to lock the phone. So now, we can't unlock the phone. We need to forbid user to add a lock password but we don't want to add one because if the phone is sleeping, a user should be able to unlock it.
**Edit : ** We can't block user from accessing settings
So, is there a solution for that ? like a "ShowRoom" mod ?
If you need more precisions, please ask.
Thanks
First you need to add the following attribute to your activity:
android:launchMode="singleTask"
Then add two categories to the intent filter :
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
The result could look something like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dummy.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.dummy.app.MainActivity"
android:launchMode="singleTask"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
</application>
</manifest>
please read this answer to block exiting app
https://stackoverflow.com/a/16333555/5223973
if you want to use any third party app to lock your app you can use any
android parental control apps

HOME activity will not show up or act as home activity

This is my first time asking a question on on here, but I have found the answer to innumerable questions I've had before on here. However, I just can't make this one work. I'm simply trying to write an app to replace the homescreen. Here is what I am trying, and I can't see what I'm missing.
To keep it as simple as possible, I reduced it to just this testing application. The only thing I changed after starting a new project was the manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hometesting"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
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>
<activity
android:name=".HomeActivity"
android:theme="#style/AppTheme"
android:launchMode="singleTop"
android:stateNotNeeded="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.categoty.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I have tried it both in the emulator and my own phone, in the latter, it doesn't show up in the chooser. I can select it as the default home application in the user settings, but when i hit the home button, it just brings up the chooser without my app as an option. The pre-installed home screens and one other app that I downloaded show up as options, but my app doesn't. In the emulator, a click on the home button just brings up the default homescreen.
I have tried it with and without the separate launcher activity, and with and without the LAUNCHER intent. I have tried installing, uninstalling, restarting, and every permutation thereof.
All I want is for the home button to lead back to an activity that I wrote. Any help would be greatly appreciated.
Update: I also tried it on a generic cheap Chinese device, and still nothing.

Android manifest for USBAccesory

I am making an app that communicates with a piece of usb hardware made by my company (this is the only app allowed to talk to the usb accessory, it's not a public api). I am having difficulties setting up the proper launch modes in the manifest.
There are three components to the app: the main activity, a login activity, and the USBService.
I'm assuming the intent for the main goes to the login activity, and the intent for the usb goes to the USBService, but I am not sure if I do this, will this start the service if the app is not running? More over, if it does, how do I fetch an already existing service?
What type of structure should I be looking at for the manifest file? (specifically, intent-filters, and appropriate launch modes... I've read a few documents about the launch modes but I am still not sure I quite understand... There should only ever be at most one instance of each activity/service, and they need to communicate together.
edit: it is not necessary for communications to start before the app is open, nor is it necessary to launch the app automatically when the usb is connected.
edit: my manifest as it stands, looks like:
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="mainpackage.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<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_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
<activity
android:name="mainpackage.LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<service android:name="updater.USBService"
android:exported="false" >
<!--
-->
</service>
</application>
in your manifest add
<manifest ...>
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk android:minSdkVersion="12" />
In this case, the following resource file should be saved in res/xml/device_filter.xml and specifies that any USB device with the specified attributes should be filtered:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1234" product-id="5678" class="255" subclass="66" protocol="1" />
</resources>
Hope this help.
Your manifest looks good,
I think you make a good choice for putting the intent-filter "android.hardware.usb.action.USB_ACCESSORY_ATTACHED" in the mainActivity and start the application in this activity,
and again I think it's a good choice to start your mainActivity in SingleTop launch mode,
because if an instance of the mainActivity already exists at the top of the current task, the system going to launch this activity, no new instance of this activity will be created.
For a best understanding of the different launch mode available in android,
I think this link may help you :
http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
To make a long story short I think you'll be all set with this manifest as is.
To Use Android Devices min SDK version should be set to 12 and need to declare following line in AndroidManifest.xml file
<>
<uses-sdk android:minSdkVersion="<version>" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
<activity ...>
...
<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>

Selecting default action on Android

I am trying to build an application that would replace a default action on Android. The problem is that when action should be performed i get "Select Action" dialog with no checkbox to select it as default. I think i should be getting "Complete Action Using" dialog (which in turn has the checkbox). I do not understand how I can make Android to offer me the "Complete ..." dialog. My manifest file is as:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="si.cetrtapot.mobiris"
android:versionName="1.0"
android:versionCode="1" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc"
android:required="true" />
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:debuggable="true" >
<activity android:name=".ReadTagActivity"
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>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc" />
</activity>
</application>
</manifest>
Can anybody tell me what is wrong?
The way intent-filters work is that the PackageManager has all these applications registered with it via the Manifest that is found per application. Specifically when an application falls un a certain Intent-Filter, it will then be added to the list of applications that have those kinds of Intent-Filters declared in their Manifest.
For instance say my application, handles the: Intent.ACTION_SEND this means that my application will show up in the list of application that hand particular action. Which would include, the default MMS/SMS application and any other applications the user has that has this, including MY application if the user has it installed.
You should begin by understanding what "default action" even means. Understanding this will help you how to solve your problem.
For your reference:
Intent
Intent.CATEGORY_DEFAULT
I do not believe that anything is wrong. I don't believe NFC intents were meant to have a default app unless you have very specific intent filtering for Ndef formatted cards. I did this for my job because we wanted just our app to pop up with our tag. Otherwise it would just be in a list all the time (which is annoying).

How to keep an Android app running indefinitely?

I am writing an Android app which must always be running in the background until the user exits it from the app's menu. But now I notice that in Android after some time my app is stopped by itself without user intervention.
Any idea how to make sure my app will always be running in the background?
You need to run a Service of your own.
http://developer.android.com/reference/android/app/Service.html
If you need to run at all times, look into a Service and startForeground. If you can let your Service die but get restarted, look into onStartCommand and START_STICKY.
AndroidMainfest.xml looks like this with presistent=true:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="7" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:persistent="true">
<activity
android:name="com.example.test.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>
</application>
</manifest>
“While the app development documentation does explain the role of
android:persistent, the use of that attribute is reserved for apps that
are built within the AOSP.”
– Embedded Android
For your application, in the manifest xml, put:
android:persistent="true"

Categories

Resources