1

我正在开发一个小部件应用程序,我的问题是运行应用程序时出现以下消息:未找到启动器活动!,启动只会同步设备上的应用程序包!

这是代码:

安卓清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pack"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >


        <receiver android:name=".MeteoWidget"
            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/my_widget_provider" />
        </receiver>

        <activity android:name="TabsMeteoActivity" android:theme="@android:style/Theme.NoTitleBar"></activity>
        <activity android:name="MenuMeteoActivity"></activity>
        <activity android:name="MaVilleActivity"></activity>
        <activity android:name="MeteoJourActivity"></activity>
        <activity android:name="PrevisionSemaineActivity"></activity>
        <activity android:name="ParametresActivity"></activity>


    </application>

</manifest>

Meteowidget.java

public class MeteoWidget extends AppWidgetProvider {


     @Override
     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {  
        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];         
        // Create an Intent to launch TabsMeteoActivity       
        Intent intent = new Intent(context, TabsMeteoActivity.class);  
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);    
        // Get the layout for the App Widget and attach an on-click listener       
        // to the widget     
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);   
        views.setOnClickPendingIntent(R.id.Layout_widget, pendingIntent);       

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

主要的.xml

    <?xml version="1.0" encoding="utf-8"?>

                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/Layout_widget"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:layout_gravity="center"
         android:background="@drawable/widget_layout"
         android:focusable="true" 

         >


        <TextView android:id="@+id/date_jour"
         android:text="Vendredi 5 Mai"
         android:textStyle="italic"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:layout_gravity="left"
         android:layout_marginTop="0dip"        
         android:textColor="#ffffffff"
         android:textSize="12sp"/>




        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/Layout2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:layout_gravity="left"

         >
           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/Layout3"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:orientation="vertical"
               android:layout_gravity="left"

            >
            <TextView
               android:id="@+id/txt_ville"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="3dip"
               android:layout_marginTop="40dip"
               android:textSize="16sp" 
               android:text="Tunis"
                android:textStyle="bold"
               android:textColor="@android:color/white"/>


            </LinearLayout>

           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/Layout4"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
               android:layout_gravity="left"

            >
             <ImageView
               android:id="@+id/img_meteo"
               android:layout_width="70dp"
               android:layout_height="70dp"               
               android:layout_marginTop="0dip"
               android:layout_marginLeft="0dp"
               android:src="@drawable/sunny_64"

              />

            <TextView
                   android:id="@+id/txt_temp"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="3dip"
                   android:layout_marginTop="25dip"
                   android:textSize="16sp" 
                   android:textStyle="bold"
                   android:textColor="#FFD700"
                   android:text="25°"/>
           </LinearLayout>

           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:id="@+id/Layout5"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:orientation="vertical"
               android:layout_gravity="left"

            >
               <TextView
                android:id="@+id/txt_temp_min"                
                android:textSize="12sp" 
                android:textColor="@android:color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:layout_marginTop="20dip"
                android:textStyle="bold"
                android:text="Min:22°"/>

              <TextView
                android:id="@+id/txt_temp_max"
                android:textSize="12sp" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dip"
                android:layout_marginLeft="10dip"
                android:textStyle="bold"
                android:textColor="#FF0000"
                android:text="Max:26°"/>

         </LinearLayout>


   </LinearLayout>

</LinearLayout>

my_widget_provider.xml

<?xml version="1.0" encoding="utf-8"?>
                <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
     android:minWidth="160dip"
     android:minHeight="80dip"
     android:updatePeriodMillis="10000"
     android:initialLayout="@layout/main"

/>
4

1 回答 1

0

您应该将一个 Activity 提升为可启动以消除此消息。

您可以通过将以下内容添加到您的一项活动中来做到这一点(将其放在活动标签中):

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
于 2012-06-12T20:25:16.683 回答