2012-01-09 59 views
27

我有一個我在Android 2.1上創建的小部件,它已經很好並且在市場上銷售。Android 4.0:小部件沒有出現?

我有一個用戶抱怨說,他買了它,它從未出現在他的Android 4.0設備上。

我加載了4.0模擬器,從Eclipse運行它,它報告了一個成功的安裝,事實上我可以看到它列在「Widget Preview」應用程序中,我可以在那裏運行它,看起來很好,但它沒有出現在「小工具」下的任何地方 - 我實際上找不到它將其拖動到主屏幕!我認爲這與用戶所看到的是一樣的。

任何想法這裏發生了什麼? 爲什麼它在2.1中很好,但即使在安裝成功後,它也不會出現在4.0的列表中。

這是我的佈局\ widget.xml文件,如果這是任何幫助:

<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TextView android:layout_width="wrap_content" android:id="@+id/blankspot" android:layout_height="5dp" android:gravity="center" android:shadowDy="1" android:shadowDx="1" android:layout_centerHorizontal="true"></TextView> 
    <ImageButton android:layout_below="@+id/blankspot" android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/widgetIconButton" android:layout_centerHorizontal="true" android:scaleType="centerCrop" android:src="@drawable/volumeprofilesplus" android:background="@null"></ImageButton> 
    <ImageView android:layout_width="60dp" android:layout_height="20dp" android:id="@+id/override" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:scaleType="fitXY" android:background="@null" android:src="@drawable/overredcaps" android:visibility="invisible"></ImageView> 
    <ImageButton android:layout_below="@+id/widgetIconButton" android:layout_width="70dp" android:layout_height="30dp" android:id="@+id/widgetSettingsButton" android:layout_centerHorizontal="true" android:scaleType="fitXY" android:src="@drawable/settings" android:background="@null"></ImageButton> 
</RelativeLayout> 

和XML \ widget_provider.xml:

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

請發表您的{}小部件的.xml – Force 2012-01-09 20:46:47

+0

清單或提供XML? Lemme弄清楚如何正確粘貼代碼... – JamieB 2012-01-09 20:56:02

+0

'layouts \ widget.xml' - 是一個「錯字」還是你的提供者xml真的在佈局文件夾中?應該放在'res/xml/widget.xml'中。 – 2012-01-09 21:07:55

回答

17

因此,這裏是我想出瞭解決方案:

您需要將出現在發射活動。所以首先我們有葉奧爾德部件接收器,像這樣:

<receiver android:name=".VolumeProfilesWidget" android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />     
     <!-- Broadcast Receiver that will also process our self created action --> 
     <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_RECEIVER"/>    
    </intent-filter> 
    <meta-data android:name="android.appwidget.provider" android:resource="@xml/volumeprofiles_widget_provider" /> 
</receiver> 

然後我們需要一些活動,主要和啓動設置:

<activity android:name=".MainActivity" 
      android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" />     
     <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_CONFIGURE"/> 
    </intent-filter> 
</activity> 

至於我可以告訴你必須這樣做即使你的小部件只是一個純粹的小部件而沒有相關的活動。至少,做一個虛擬活動,啓動一個屏幕,上面寫着「您的小部件已準備好使用!在小部件下查找並將其拖到主屏幕上!」

就我而言,我的小部件在推送時啓動了一項活動,因此我將該活動設置爲LAUNCHER/MAIN,並添加了一次性彈出對話框,基本上說「您可以將其作爲應用程序運行,但可能會想要改爲使用小部件「。

請注意,在4.0模擬器上,我從來沒有讓我的小部件在第一次安裝之前顯示出來。簡單地將一個活動設置爲MAIN和LAUNCHER似乎足以使小部件顯示出來。

+0

這只是模擬器的問題,還是會影響Android 4.0設備? – 2012-01-16 02:01:34

+1

顯然它確實。請參閱[問題24208](http://code.google.com/p/android/issues/detail?id=24208) – 2012-01-16 02:08:16

+3

是的,它也在設備上。我第一次聽到一位客戶購買4.0設備的應用程序,但無法找到它。他能夠通過重新啓動來顯示它,但我不認爲「長時間關閉並重新啓動」是一個非常好的解決方案。 (儘管它在微軟工作了很多年。) – JamieB 2012-01-16 02:49:31

1

您需要手動啓動相關的應用程序在至少一次讓小部件出現。在此之前,它是在一個非可運行狀態,它不會接收廣播等

+0

啊,所以在重啓時我看到它可能是巧合,真正有它在那裏打開它的widget預覽? 除了小部件預覽,我們還可以告訴人們「手動啓動關聯的應用程序」嗎?從技術上講,這只是一個小部件 - 「應用程序」下沒有任何東西可以顯示。 – JamieB 2012-01-10 19:00:04

+0

可能是,我沒有真正詳細看過這個。添加一個簡單的測試活動並嘗試一下。如果事實證明這是必需的,你可以用它來改變設置,給出說明等。不理想,我同意。 – 2012-01-11 01:09:20

+1

我拒絕了,因爲我不認爲這是嘗試。我有一個純粹的小部件,我曾在2.3和4.1下運行過一個關聯的應用程序。我必須承認,我來到這裏是因爲那個小部件後來變得不可思議,但是一段時間以來,它作爲一個'純粹的小部件'運行良好。 – Tom 2012-08-18 15:43:27

3

得到了同樣的問題。我通過在我的appwidgetprovider.xml(located in res/xml)中刪除<PreferenceScreen>標籤來修復它。

+2

我從來沒有PreferenceScreen標籤的任何地方。 – JamieB 2012-10-18 13:58:12

9

天之後我想通了,該解決方案

所以讓我們去任何你的活動,這將是當你打開應用程序,並推出的主要活動的 只添加這行

sendBroadcast(新意圖(Intent.ACTION_MAIN).addCategory(意向。CATEGORY_HOME));

爲例

public class Default class extends Activity { 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
     sendBroadcast(new Intent(Intent.ACTION_MAIN) 
     .addCategory(Intent.CATEGORY_HOME)); 
    setContentView(R.layout.main); 



} 

就是這樣,這會得到主要的應用程序現在正在運行的系統,它會得到小部件出到發射:)簡單的線條就是它不修改任何東西清單 只是保持你開發的應用程序的方式,顯示小工具在以前的版本中正常顯示小部件< 4.x

+0

這個工程。謝謝你。 – 2014-03-14 03:37:19

+0

也爲我工作 – Coderji 2014-12-29 10:19:06