2014-06-09 5 views
0

위젯이 잘 작동하고 위젯을 두드려 활동을 열 필요가 없습니다. 하지만 나는 런처로 액티비티를 시작해야 할 때마다 수동으로 액티비티를 열고 싶다. 문제는 해당 액티비티가 appwidgetprovider의 OnReceive 메소드로 시작되지만 해당 런처 액티비티에 아이콘이 없다는 것입니다. 처음 시작할 때 닫을 때 다시 열 수있는 아이콘 (활동)을 찾을 수 없습니다.동시에 활동과 위젯을 시작하고 싶습니다.

여기 appwidgetprovider 클래스의

public class CurrentMoodWidgetProvider extends AppWidgetProvider { 
public static final String WIDGETTAG = "WidgetMood"; 

@Override 
public void onReceive(Context context, Intent intent) { 
    // TODO Auto-generated method stub 
    super.onReceive(context, intent); 

    Intent myIntent = new Intent(context, Picture.class); 
    // FLAG_ACTIVITY_NEW_TASK is needed because we're not in an activity 
    // already, without it we crash. 
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(myIntent); 
} 


@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
     int[] appWidgetIds) { 
    super.onUpdate(context, appWidgetManager, appWidgetIds); 

    Log.i(WIDGETTAG, "onUpdate"); 
    final int N = appWidgetIds.length; 

    // Perform this loop procedure for each App Widget that belongs to this provider 
    for (int i=0; i<N; i++) { 
     int appWidgetId = appWidgetIds[i]; 

     Log.i(WIDGETTAG, "updating widget[id] " + appWidgetId); 

     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetlayout); 

     Intent intent = new Intent(context, CurrentMoodService.class); 
     intent.setAction(CurrentMoodService.UPDATEMOOD); 

     intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 
     PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); 

     views.setOnClickPendingIntent(R.id.widgetBtn, pendingIntent); 
     Log.i(WIDGETTAG, "pending intent set"); 

     // Tell the AppWidgetManager to perform an update on the current App Widget 
     appWidgetManager.updateAppWidget(appWidgetId, views); 
    } 
    }  
    } 

답변

0

이 동시에 활동에 매니페스트 & 수신기를 정의 .. 내 코드입니다. 예.

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="Your Package Name" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <receiver android:name="MyWidgetProvider" > 
     <intent-filter > 
      <action 
       android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 

     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_info" /> 
    </receiver> 
</application> 
+0

내 매니페스트 같은 단지 수행하지만 여전히 그냥가 출시 전에 같이하지만 아이콘이 – user3720615

+0

내가이 있음을 지울 발견이 있음을 닫은 후 .. 내 런처 활동에는 아이콘이 없었다 또한 "CurrentMoodService"라고 불리는 서비스이며 onUpdate 메서드에 의해 완벽하게 호출됩니다. 또한으로 매니페스트에 추가했습니다. – user3720615

관련 문제