Bardzo proszę o pomoc, bo zaraz chyba wylewu dostanę. Próbuję odpalić przykładowy widget na telefonie, ale za cholerę mi się to nie udaje. Kod:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andrzej.beawidget" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="Main">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget"/>
</receiver>
</application>
</manifest>
Widget.xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android">
android:minWidth="144dp"
android:minHeight="72dp"
android:initialLayout="@layout/main"
android:updatePeriodMillis="86400000"
</appwidget-provider>
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Main">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/ic_sync_button"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="59dp"
android:layout_marginEnd="59dp"
android:layout_marginBottom="134dp" />
</RelativeLayout>
Klasa AppWidgetProvider:
public class Main extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context,appWidgetManager, appWidgetIds );
for(int i=0; i<appWidgetIds.length;i++) {
int appWidgetId=appWidgetIds[i];
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://onet.pl"));
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent,0);
RemoteViews views=new RemoteViews(context.getPackageName(), R.layout.main);
views.setOnClickPendingIntent(R.id.imageButton, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
Konfiguracja: http://imgur.com/7Ap0opf
Przy wysyłaniu na telefon nie wyświetla żadnych błędów, ale nigdzie tego widgetu na telefonie nie widzę. Jest widoczny jedynie w ustawieniach w zainstalowanych aplikacjach. Help pls bo osiwieję przez to :)