在Android手機的AppWidget上如何打開一個Activity?
一、onUpdate()函數中
//創建一個Intent對象
Intent intent = new Intent(context,MyActivity.class);
intent.setAction(broadCastString);
//設置pendingIntent的作用
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.appwidgetlayout);
//綁定事件
remoteViews.setOnClickPendingIntent(R.id.image_wifi,pendingIntent);
//更新Appwidget
appWidgetManager.updateAppWidget(appWidgetIds,remoteViews);
二、AndroidManifest.xml中注冊MyActivity
<activity
android:name="com.example.myappwidget.MyActivity"
android:label="hehe" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
大體的步驟是如此,具體你可以根據自己的要求做出修改