2013-10-05 24 views
1

我是新來的小工具在Android中,同時環顧四周,發現人們首次創建他們的小工具項目時沒有選中「創建活動」設置,所以我也這樣做了。現在,當我跑我的小工具我得到這個錯誤:找不到laucher活動! Android Widget

[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> 

注:此部件沒有完全結束不過,我應該還是可以到我的當前控件下載到主屏幕,即使部件沒有任何功能呢。

回答

1

當您沒有啓動器活動時,構建環境不知道如何啓動您的應用程序。因此,你會得到錯誤。

由於在第二消息中指出,

The launch will only sync the application package on the device!

這基本上意味着你需要自己的小部件添加到您的主屏幕,應用程序應該得到安裝/通過構建系統更新。


真正的問題是最後一行

Automatic Target Mode: Unable to detect device compatibility. Please select a target device.

你應該嘗試在IDE中手動選擇一個目標設備,也可能是版本您的應用程序,你是模擬器/設備之間的問題用於調試。一個常見問題是使用谷歌API,這需要一個安裝谷歌組件的真實設備,請參閱this question

+0

我通過真實設備選擇的目標設備從現在彈出的選擇菜單我得到這個錯誤(請檢查更新的問題) – user1628978

1

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> 
+0

我在接收器中定義了intent-filer,但也許我做錯了?還是我必須使用一種活動? – user1628978

+0

1)你需要運行一些東西來調用這個小部件。無論這是您的項目的MainActivity,還是其他可以稱之爲的東西。 2)正如dst所強調的那樣,你將apk安裝到設備上似乎有問題。你能在模擬器上工作嗎? –

+0

要重新響應: 1)我說我當前類的問題,請看一看。 – user1628978