Hey,
I'm doing a task that, in my opinion should be relatively simple. I have an
application on android, and I want to make a widget that, when clicked on,
launches the application. I've followed many forum posts online, and yet
have come up short. I would really appreciate any insight into the issue.
Thanks in advance. The following are the details of my widget:
*My Widget Class:*
package com.followup;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class IconWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(final Context context, final AppWidgetManager
appWidgetManager, final int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
final int appWidgetId = appWidgetIds[i];
final Intent intent = new Intent(context, FollowUpActivity.class);
//FollowUpActivity.class is the class of the main app
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
final RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.icon_widget_layout);
views.setOnClickPendingIntent(R.id.image_in_widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
*Manifest File:*
*
*
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.followup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!-- <uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
.
.
.
<!-- Home icon widget -->
<receiver android:name="IconWidgetProvider"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/homescreeniconinfo" />
</receiver>
<activity
android:name=".FollowUpActivity"
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>
*homescreeniconprovider.xml*
*
*
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dip"
android:minHeight="72dip"
android:updatePeriodMillis="0"
android:initialLayout="@layout/icon_widget_layout" >
</appwidget-provider>
*icon_widget_layout.xml*
*
*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button android:name="@+id/image_in_widget"
android:contentDescription="@string/iconDescription"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".50"
android:clickable="true"
/>
</LinearLayout>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en