0

我制作的小部件可以很好地进入模拟器和真实设备,没有错误,但是当我点击按钮在小部件上打开一个新活动时,它没有打开,我在 Logcat 中得到的只是这个:

10-12 12:54:23.721: I/ActivityManager(289): START u0 {dat=intent: flg=0x10000000 cmp=com.example.awesomefilebuilderwidget/.Drag_and_Drop_App bnds=[56,639][209,735] (has extras)} from pid -1

我不明白为什么它不打开我的活动 (Drag_and_Drop_App.java) 这是我的 AppProvider 中的代码:

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    // TODO Auto-generated method stub
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    Random r = new Random();
    int randomInt = r.nextInt(1000000000);
    String rand = String.valueOf(randomInt);

    final int N = appWidgetIds.length;

    for (int i = 0; i < N; i++){
        int awID = appWidgetIds[i];
        RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.widget);
        v.setTextViewText(R.id.tvwidgetUpdate, rand);
           Intent configIntent = new Intent(context, Drag_and_Drop_App.class);

            PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);

            v.setOnClickPendingIntent(R.id.bwidgetOpen, configPendingIntent);

        appWidgetManager.updateAppWidget(awID, v);
    }

}

请注意,我的 WidgetConfig.java 中也有此编码(安装小部件时首先弹出的屏幕以收集小部件的名称):

    @Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    String e = info.getText().toString();

    RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget);
    views.setTextViewText(R.id.tvConfigInput, e);

    Intent in = new Intent(c, Drag_and_Drop_App.class);
    in.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // Make the pending intent unique...
    in.setData(Uri.parse(in.toUri(Intent.URI_INTENT_SCHEME)));

    PendingIntent pi = PendingIntent.getActivity(c, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.bwidgetOpen, pi);

    awm.updateAppWidget(awID, views);

    Intent result = new Intent();
    result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);
    setResult(RESULT_OK, result);

    finish();
}


}

如果有帮助,这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<receiver android:name="com.example.awesomefilebuilderwidget.AFBWidget" 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="@xml/widget_stuff"/>

</receiver>

<activity android:name="com.example.awesomefilebuilderwidget.WidgetConfig" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>

</intent-filter> 

</activity>   

<activity android:name="com.example.awesomefilebuilderwidget.Drag_and_Drop"     android:label="@string/app_name"></activity>
</application>

</manifest> 
4

0 回答 0