English 中文(简体)
4. 未收到预估结果的甲型六氯环己烷
原标题:Android AppWidget not receiving APPWIDGET_ENABLED intent

我试图利用AlarmManager的班级创建我的第一个应用植被,以便我能够比每30分钟更经常地更新。 下面是:,这是建立我的植被的基础,但出于某种原因,我无法及时获得最新情况。 似乎我从未收到过任何PWIDGET_ENABLED意向书,这些意向将击落我的“援助目标提供人”的令人振奋的事件。

这里是我的应用植被提供人的明确定义:

    <receiver 
       android:name="com.myapp.android.appwidget.MarketTimingAppWidgetProvider"
       android:label="@string/appwidget_markettiming_label">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
            <action android:name="@string/appwidget_markettiming_updateintent" />           
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
                   android:resource="@xml/appwidget_markettiming_info" />
    </receiver>

这里是我的“植被提供者”守则:

public class MarketTimingAppWidgetProvider extends AppWidgetProvider {

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    final int N = appWidgetIds.length;

    Log.d("myLogger", "onUpdate");
    // 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.d("myLogger", "Updating Widget: " + appWidgetId);
        updateWidget(context, appWidgetManager, appWidgetId);

    iii

iii

@Override
public void onEnabled(Context context) {
    super.onEnabled(context);

    Log.d("myLogger", "onEnabled running");
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 1);
    alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 
                              1000, createClockIntent(context));   
iii

public void onDisabled(Context context) {
    super.onDisabled(context);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(createClockIntent(context));
iii

public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    Log.d("myLogger", "Intent Received " + intent.getAction());
    String widgetIntent = context.getResources().getString(R.string.appwidget_markettiming_updateintent);

    // This code fires when my custom intent is received
    if(widgetIntent.equals(intent.getAction())) {
        ComponentName thisAppWidget = new ComponentName(context.getPackageName(), getClass().getName());
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int ids[] = appWidgetManager.getAppWidgetIds(thisAppWidget);
        for(int appWidgetId: ids) {
            updateWidget(context, appWidgetManager, appWidgetId);
        iii
    iii

iii

private void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_markettiming);
    views.setTextViewText(R.id.widget_text, "Update: " +  
            DateFormat.getDateTimeInstance(
                    DateFormat.LONG, DateFormat.LONG).format(new Date()));

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

iii

private PendingIntent createClockIntent(Context context) {
    String updateIntent = context.getResources().getString(R.string.appwidget_markettiming_updateintent);
    Log.d("myLogger", "my intent: " + updateIntent);
    Intent intent = new Intent(updateIntent);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
iii

iii

当我看一下LogCat时,我采用的收受方法所忽略的唯一意图是初步的PRWIDGET_UPDATE意图,而现在唯一的退步就是最新的呼吁。 我已尝试将“PEWIDGET_ENABLED”的意图纳入我的植被图(尽管“T”告诉我,这应该由我的植被自动接收)。 它没有工作。 在这里,我没有什么东西?

最佳回答

你的发言有误。 本要素中的行动名称:

<action android:name="@string/appwidget_markettiming_updateintent" />

应以实际扼杀而不是提及代替。 因此,应该这样:

<action android:name="com.myapp.android.appwidget.action.MARKETTIMING_UPDATE" />

或您在以下各项价值观/内容中拥有的任何东西:<string name=“appwidget_markettiming_updateintent”> 内容。

问题是,广播员不接收AlarmManager的广播。 我先用你的代码创立了一个项目,只将这一指示数(并给价值/指示当然是xml)和所有工作罚款添加了适当的价值。

此外,您不妨将<条码>第2项参数改为<条令/代码>,但仅限<条码>。

问题回答

很明显,它从支持者那里分离出来,然后又重新陷入困境。 现在,我还要问一看预想,一看我去去去了。 如同我所期望的那样,有人发射DISABLED的意图。 我仍然有一个问题,即警报管理员实际上没有像我所期望的那样向我的习惯信士开火,但我需要研究一个单独的问题。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签