1

我有一个由服务管​​理的 android 小部件。在onStartCommand我做:

for (int widgetId : allWidgetIds) {

    RemoteViews remoteViews = new RemoteViews(this
            .getApplicationContext().getPackageName(),
            R.layout.main);         

    // Register an onClickListener
    Intent clickIntent = CreateWifiSettingsIntent(this.getApplicationContext());

    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, clickIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_textview, pendingIntent);

    appWidgetManager.updateAppWidget(widgetId, remoteViews);

    Log.i(LOG, "onClickListener Registered");
    }

CreateWifiSettingsIntent正在简单地构建一个 PendingIntent:

public Intent CreateWifiSettingsIntent(Context context) {

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
    final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");

    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    /* this Log will be called whenever the intent is created */
    Log.i(LOG, "Intent created: com.android.settings.wifi.WifiSettings");

    return intent;

}   

我想做的是添加一个Log.i()调用,每次用户按下按钮时都会执行该调用。我有办法可以在这里添加这个吗?

4

0 回答 0