My widget won't install. I'm trying to install a home screen widget using android. I've put the widgetprovider in the manifest along with a configuration class. It just doesn't show up in the list of widgets and I hence can't install it! Console gives no errors.
The update widget receiver is there in the manifest. But the widget isn't even created so what's the point? The widget won't get created!
I've created the layout, created the widget information file and filled in the fields, registered it in the manifest, created the classes, it still won't work.
<receiver
android:name=".WidgetProvider"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.WIDGET_PROVIDE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_info"/>
</receiver>
<activity
android:name=".WidgetConfig"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.WIDGET_CONFIG" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
There is an error in your manifest. The intent filter should contain
action android:name="android.appwidget.action.APPWIDGET_UPDATE"
not:
action android:name="android.appwidget.action.WIDGET_PROVIDE"
If you have more than one widget provider, each one needs its own receiver containing this action. Here is an example for one widget provider:
<receiver android:name=".WidgetProvider"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="#layout/widget_provider_2x1"/>
</receiver>
Related
my application is using a widget which is declared in the manifest as follows:-
<receiver android:name=".ui.widgetprovider.DialerWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info_dialer" />
</receiver>
Now what I wanted to know was, that is there any way that I could declare a BroadCast receiver with the same intent filter that of the appwidget provider ?
Something like
<receiver android:name=".BroadcastReceiver.WidgetEventListnerReceiver" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
</receiver>
So that I can catch the intents being passed to the widget? Is that possible ?
Any help would be greatly appreciated.
I would like to have two main activities in my app. So in my manifest I put:
<activity
android:name="mypackage1.MainActivity"
android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="mypackage2.MainActivity2"
android:label="#string/title_activity_main2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Two icons are created in my apps menu. But when I click on each of them the first activity MainActivity is always launched. Is it possible to have two main activities? If so, what's wrong with what I did?
Thanks
The LAUNCHER intent filter is what determines what shows up in the app drawer/launcher. That is why you get two icons shown up.
However, you also set the DEFAULT intent filter, which sets the default Activity for the whole package. Since you set it twice, you get the problem of precedence of the first/latest registered. When you remove the DEFAULT filter, you will be able to start whatever you click on in the launcher.
In short, remove the following line from both Activities:
<category android:name="android.intent.category.DEFAULT" />
Yes, just mark two or more of your <activity>s as LAUNCHER within your manifest.
In addition you have to set the android:taskAffinity attribute on both of your Launcher-Activities which specify the exact package and Activity to be started.
<activity android:label="MyApp" android:name=".MyApp" android:taskAffinity="com.example.MainActivity">
<intent-filter>
<action android:name=".MyApp"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:label="Settings" android:name=".Settings" android:taskAffinity="com.example.SettingsActivity" >
<intent-filter>
<action android:name=".Settings"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Use android:documentLaunchMode="intoExisting", to launch a separate task based on the intent's Component name and data URI. Without this (by default), the activity will share all the same activities, as android:documentLaunchMode default to none.
intoExisting: The system searches for a task whose base intent's ComponentName and data URI match those of the launching intent. If the system finds such a task, the system clears the task, and restarts with the root activity receiving a call to onNewIntent(android.content.Intent). If the system does not find such a task, the system creates a new task. source
<activity
android:name=".CameraActivity"
android:exported="true"
android:documentLaunchMode="intoExisting"
android:label="#string/app_1_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ProfilePoseNetActivity"
android:exported="true"
android:documentLaunchMode="intoExisting"
android:label="#string/app_2_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The intention of potroae using task affinities to prevent your 2 activities from sharing the same task. However, it is annoying to have to select a task name, i.e. com.example/SettingsActivity for every task you want to launch separately.
When I change the namespace of my widget provider, the widget goes blank and doesn't work until I delete it and add it again.
How would one change the namespace and the receiver name for a widget without breaking already placed widgets.
Before rename:
<receiver android:name="com.creativitality.labs.timezoneswidget.WidgetProvider" android:label="#string/widget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info_large" />
</receiver>
After moving and renaming provider:
<receiver android:name="com.creativitality.labs.timezoneswidget.widget.WidgetLarge" android:label="#string/widget_4x1" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info_large" />
</receiver>
For activities, you can create an <activity-alias> element in your manifest that points to the new name of the <activity>.
There is no solution for receivers. <receiver-alias> does not exist. Your receiver must keep its original name forever or it will break.
I want to start a service in an APK.
I tried to use as following:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<service android:name =".TestServcie">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>
</application>
Any ideas?
Thanks
You can write a BroadcastReceiver and run the Service after receiving the Intent. For example after device boot-up or other Intent that you need.
<receiver android:name=".StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
No you can't.
Create a simple Activity which starts the service and simply provides some feedback to the user (to tell them the service has started for example) and set that Activity with the MAIN/LAUNCHER intent.
My problem is thus; I am new to programming on the ANDROID platform and have a 'working' application that piggy-backs on the API-Docs example. I wish it to launch three tabs one containing a list of reports, one a form to file a report and the last to show the geo-located reports. It doesn't appear as a separate application, it instead appears as a list to be launched by the API-Docs example. Below is my manifest code...
<activity android:name=".HelloFlamingos">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".Controls2" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
<activity android:name=".List1" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
<activity android:name=".ReviewTab" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
HelloFlamingos is the initial page that I wish to be displayed, I realise that the intents for this are wrong, have thought about using category: VIEWS, action: DEFAULT, however is seemingly unwilling to work. Thanks!
In what context is the activity started? If you're looking to have the HelloFlamingos activity the first displayed from the Android OS, you should change its category in the manifest to category.LAUNCHER.
If you're looking to start the activity from elsewhere in your app, create an Intent which matches what you've specified (category.SAMPLE_CODE) and use startActivity or startActivityForResult.