2011-01-03 7 views
0

私は私のクリック意図を作るのに助けが必要です。私はappwidgetproviderでそれらを持っていましたが、サービスに移行することに決めましたが、私はそれを動作させるのに問題があります。以下は私のインテントサービスのコード全体です:インテントが機能していないサービス。助けが必要

public class IntentService extends Service { 

static final String ACTION_UPDATE = "android.tristan.widget.digiclock.action.UPDATE_2"; 
private final static IntentFilter sIntentFilter; 
public int layoutID = R.layout.clock; 
int appWidgetIds = 0; 

static { 
    sIntentFilter = new IntentFilter(); 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

@Override 
public void onStart(Intent intent, int startId) { 
    super.onStart(intent, startId); 
} 

@Override 
public void onCreate() { 
    super.onCreate(); 
    registerReceiver(onClickTop, sIntentFilter); 
    registerReceiver(onClickBottom, sIntentFilter); 
Log.d("DigiClock IntentService", "IntentService Started."); 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    unregisterReceiver(onClickTop); 
    unregisterReceiver(onClickBottom); 
} 

private final BroadcastReceiver onClickTop = new BroadcastReceiver() { 

@Override 
    public void onReceive(Context context, Intent intent) 
{ 

    if(intent.getAction().equals("android.tristan.widget.digiclock.CLICK")) 
    { 
     PackageManager packageManager = context.getPackageManager(); 
     Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); 

     String clockImpls[][] = { 
       {"HTC Alarm Clock", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, 
       {"Standar Alarm Clock", "com.android.deskclock", "com.android.deskclock.AlarmClock"}, 
       {"Froyo Nexus Alarm Clock", "com.google.android.deskclock", "com.android.deskclock.DeskClock"}, 
       {"Moto Blur Alarm Clock", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"} 
     }; 

     boolean foundClockImpl = false; 

     for(int i=0; i<clockImpls.length; i++) { 
      String vendor = clockImpls[i][0]; 
      String packageName = clockImpls[i][1]; 
      String className = clockImpls[i][2]; 
      try { 
       ComponentName cn = new ComponentName(packageName, className); 
       ActivityInfo aInfo = packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); 
       alarmClockIntent.setComponent(cn); 
       foundClockImpl = true; 
      } catch (NameNotFoundException e) { 
       Log.d("Error, ", vendor + " does not exist"); 
      } 
     } 

     if (foundClockImpl) { 
     Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); 
     vibrator.vibrate(50); 
     final RemoteViews views = new RemoteViews(context.getPackageName(), layoutID); 
     views.setOnClickPendingIntent(R.id.TopRow, PendingIntent.getActivity(context, 0, new Intent(context, DigiClock.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT)); 
     AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views); 
     alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(alarmClockIntent);  
    } 
    } 
} 
}; 

    private final BroadcastReceiver onClickBottom = new BroadcastReceiver() { 

     @Override 
     public void onReceive(Context context, Intent intent) 
     { 

      if(intent.getAction().equals("android.tristan.widget.digiclock.CLICK_2")) 
      { 
       PackageManager calendarManager = context.getPackageManager(); 
       Intent calendarIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); 

        String calendarImpls[][] = { 
          {"HTC Calendar", "com.htc.calendar", "com.htc.calendar.LaunchActivity" }, 
          {"Standard Calendar", "com.android.calendar", "com.android.calendar.LaunchActivity"}, 
          {"Moto Blur Calendar", "com.motorola.blur.calendar", "com.motorola.blur.calendar.LaunchActivity"} 
        }; 

       boolean foundCalendarImpl = false; 

       for(int i=0; i<calendarImpls.length; i++) { 
        String vendor = calendarImpls[i][0]; 
        String packageName = calendarImpls[i][1]; 
        String className = calendarImpls[i][2]; 
        try { 
         ComponentName cn = new ComponentName(packageName, className); 
         ActivityInfo aInfo = calendarManager.getActivityInfo(cn, PackageManager.GET_META_DATA); 
         calendarIntent.setComponent(cn); 
         foundCalendarImpl = true; 
        } catch (NameNotFoundException e) { 
         Log.d("Error, ", vendor + " does not exist"); 
        } 
       } 

       if (foundCalendarImpl) { 
       Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); 
       vibrator.vibrate(50); 
       final RemoteViews views2 = new RemoteViews(context.getPackageName(), layoutID); 
       views2.setOnClickPendingIntent(R.id.BottomRow, PendingIntent.getActivity(context, 0, new Intent(context, DigiClock.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT)); 
       AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views2); 
       calendarIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       context.startActivity(calendarIntent);  
     } 
      } 

}; 
}; 
;}; 

私はここで間違っていますか?

+0

「インテント」を送信するコードはどこですか?私はあなたの問題がどこにあるのかを感じています...また、このクラスをマニフェストのサービスとして登録しましたか?放送受信機はどうですか? –

+0

どのようなエラーが表示されますか? –

+0

私はそれをマニフェストに登録しました。私はそれが正しく始まっていることを知っています、私はlogcatでそれを見ることができます。 – tristan202

答えて

0

考えられる1つの問題は、BroadcastReceiversがプライベート内部クラスであり、IntentServiceクラス外のコードからアクセスできないことです。

+0

それはかなりおそらく原因のように聞こえる。 – Falmarri

+0

私はそれを単に私的なものから一般的なものに変えるべきですか? – tristan202

関連する問題