【问题标题】:No laucher activity found! Android Widget未找到任何 laucher 活动!安卓小部件
【发布时间】:2013-10-05 09:51:24
【问题描述】:

我是 Android 小部件的新手,环顾四周时发现人们在首次为小部件创建项目时未选中“创建活动”设置,所以我也这样做了。现在,当我运行我的小部件时,我收到了这个错误:

[2013-10-04 18:08:35 - AwesomeFileBuilderWidget] No Launcher activity found!
[2013-10-04 18:08:35 - AwesomeFileBuilderWidget] The launch will only sync the application package on the device!
[2013-10-04 18:08:35 - AwesomeFileBuilderWidget] Performing sync
[2013-10-04 18:08:35 - AwesomeFileBuilderWidget] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.

我现在认为我应该保持选中“创建活动”设置。这会是问题吗?如果是这样,我该如何更改“创建活动”设置?

顺便说一下,这是我的 Android 清单:

<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=".AwesomeFileBuilderWidget" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
     </receiver>

        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/widget_stuff"/>

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

</application>

</manifest>

这是我尝试在真实设备上运行小部件时遇到的完整错误:

[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] ------------------------------
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] Android Launch!
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] adb is running normally.
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] No Launcher activity found!
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] The launch will only sync the application package on the device!
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] Performing sync
[2013-10-04 19:02:33 - AwesomeFileBuilderWidget] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2013-10-04 19:02:46 - AwesomeFileBuilderWidget] Uploading AwesomeFileBuilderWidget.apk onto device 'HT18YMA05067'
[2013-10-04 19:02:51 - AwesomeFileBuilderWidget] Failed to install AwesomeFileBuilderWidget.apk on device 'HT18YMA05067': timeout
[2013-10-04 19:02:51 - AwesomeFileBuilderWidget] Launch canceled!

这是我的类和 xml 文件: AFBWidget.java:

import java.util.Random;

import com.example.awesomefilebuilderwidget.R;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.widget.RemoteViews;
import android.widget.Toast;


public class AFBWidget extends AppWidgetProvider{

@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);
        appWidgetManager.updateAppWidget(awID, v);
    }

}

Widget.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/tvConfigInput"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<Button
    android:id="@+id/bwidgetOpen"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<TextView
    android:id="@+id/tvwidgetUpdate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

</LinearLayout>

Widgetconfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/etwidgetconfig"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/bwidgetconfig"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button" />

</LinearLayout>

注意:这个小部件尚未完全完成,但我仍然可以将当前的小部件下载到主屏幕,即使该小部件还没有任何功能。

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    当您没有启动器活动时,构建环境不知道如何启动您的应用程序。因此,您会收到错误消息。

    如第二条消息所述,

    启动只会同步设备上的应用包!

    这基本上意味着您需要自己将小部件添加到主屏幕,应用程序应该由构建系统安装/更新。


    真正的问题是最后一行

    自动目标模式:无法检测设备兼容性。请选择目标设备。

    您应该尝试在 IDE 中手动选择目标设备,您的应用和您用于调试的模拟器/设备之间也可能存在版本控制问题。一个常见问题是使用 google API,这需要安装了 google 组件的真实设备,请参阅this question

    【讨论】:

    • 我从弹出的选择菜单中通过真实设备选择了目标设备,现在我收到此错误(请检查更新的问题)
    【解决方案2】:

    Android 需要一个启动器来知道使用什么来启动您的应用。您看到的很多内容可能是人们编写小部件库。库不需要启动器,因为您通过将库导入到您的应用程序中来使用库,该应用程序将具有启动器。

    如果您想测试您的小部件(我认为您正在使用),您需要指定一个启动器,例如:

        <activity
            android:name="com.soundconception.tabbedslider.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

    【讨论】:

    • 我在接收器中定义了intent-filer,但也许我做错了?还是我必须使用活动?
    • 1) 你需要运行一些东西来调用这个小部件。无论是您项目的 MainActivity,还是其他要调用它的东西。 2)正如 dst 突出显示的那样,您似乎在将 apk 安装到设备上时遇到了问题。你能在模拟器上运行它吗?
    • 重新回答:1)我在问题中添加了我当前的课程,请看一下。
    • 2) (抱歉回复晚了)当我尝试在模拟器上运行我的小部件时,我仍然遇到同样的错误,不仅如此,我在模拟器列表中看不到我的小部件小部件(在 Nexus 4 上),但我认为这并不重要,因为当我在真实设备上运行它时,我的小部件会显示,但我只是得到了那个错误。
    • 三天后我终于修好了!好的,确实是因为我的两个 java 类在默认包中。所以为了解决这个问题,由于我的类是通过不同的包访问的,我创建了一个新的包,它是我的应用程序(com.example.awesomefilebuilderwidget),然后将类移到那里,现在它可以正常工作了! :DD 谢谢你所做的一切,我真的很感激!
    猜你喜欢
    • 2015-04-27
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多