2016-07-17 2 views
0

AndroidStudio에서 새로운 Android 프로젝트를 만들고 앱 위젯을 만들고 구성 활동을위한 옵션을 선택하십시오. AndroidStudio는 이제 provider-info xml을 생성하고 manifest xml의 declerations와 두 Java 클래스를 생성합니다. 하나의 활동, 하나의 위젯 공급자.앱 실행 위젯 - 실행 활동을 식별 할 수 없습니다.

이것은 실행 가능해야하지만 오류가 발생합니다. 시작 활동을 식별 할 수 없습니다 : 기본 활동을 찾을 수 없습니다. 활동 시작 중 오류가 발생했습니다. 발사 필드에는 적십자가 표시됩니다.

기본 활동이 없기 때문에 이유를 알지 못합니다. 구성 활동은 위젯 제공자가 작업을 시작할 때 시작되어야합니다. 이렇게하려면 android.appwidget.action.APPWIDGET_CONFIGURE를 사용하여 activitiy에 대한 의도 필터가 있어야합니다.

인 텐트 필터 LAUNCHER 및 DEFAULT에도 범주를 추가합니다. 제공자와 활동. 하지만 여전히 오류 메시지가 나타납니다.

실행 구성에서 "아무것도 없음"을 선택하고 응용 프로그램을 실행하면 많은 오류 메시지 만 표시됩니다. 응용 프로그램 온라인 대기 : com.example.desktop_win10.myapplication | com.example.desktop_win10.myapplication.test

그러나 위젯은 설치되지 않았으며 실행되지 않습니다. 뭐가 잘못 된거야? 나는 Intellij와 AndroidStudio를 시험해 본다.

Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.desktop_win10.myapplication" > 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme" > 
     <receiver android:name=".NewAppWidget" > 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
      </intent-filter> 

      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/new_app_widget_info" /> 
     </receiver> 

     <activity android:name=".NewAppWidgetConfigureActivity" > 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

widget_info.xml :

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="40dp" 
    android:minHeight="40dp" 
    android:updatePeriodMillis="86400000" 
    android:previewImage="@drawable/example_appwidget_preview" 
    android:initialLayout="@layout/new_app_widget" 
    android:configure="com.example.desktop_win10.myapplication.NewAppWidgetConfigureActivity" 
    android:resizeMode="horizontal|vertical" 
    android:widgetCategory="home_screen" 
    android:initialKeyguardLayout="@layout/new_app_widget"> 
</appwidget-provider> 

그리고 두 개의 자바 클래스가 있습니다.



EDIT1 : 지금은 추가

카테고리 런처과 행동 메인 :

<activity android:name=".NewAppWidgetConfigureActivity" > 
    <intent-filter> 
     <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> 
     <action android:name="android.intent.action.MAIN"/> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

가끔 디버거 위젯 위젯 저장소에 경악하고 때로는하지를 시작하면 .

// If this activity was started with an intent without an app widget ID, finish with an error. 
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { 
    finish(); 
    return; 
} 

그러나 그것은 또한 나던 작업 내가 thid을 삭제하는 경우 :

는 또한 생성 된 자바 활동 클래스에서 호출 마무리 방법 인 것을 알 수있다. 기본 Google 예제가 작동하지 않는 이유를 알 수 없습니다.여기

은 자바 클래스입니다 :

활동 :

package com.example.desktop_win10.myapplication; 

import android.app.Activity; 
import android.appwidget.AppWidgetManager; 
import android.content.Context; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.EditText; 

/** 
* The configuration screen for the {@link NewAppWidget NewAppWidget} AppWidget. 
*/ 
public class NewAppWidgetConfigureActivity extends Activity { 

    int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; 
    EditText mAppWidgetText; 
    private static final String PREFS_NAME = "com.example.desktop_win10.myapplication.NewAppWidget"; 
    private static final String PREF_PREFIX_KEY = "appwidget_"; 

    public NewAppWidgetConfigureActivity() { 
     super(); 
    } 

    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     // Set the result to CANCELED. This will cause the widget host to cancel 
     // out of the widget placement if the user presses the back button. 
     setResult(RESULT_CANCELED); 

     setContentView(R.layout.new_app_widget_configure); 
     mAppWidgetText = (EditText)findViewById(R.id.appwidget_text); 
     findViewById(R.id.add_button).setOnClickListener(mOnClickListener); 

     // Find the widget id from the intent. 
     Intent intent = getIntent(); 
     Bundle extras = intent.getExtras(); 
     if (extras != null) { 
      mAppWidgetId = extras.getInt(
        AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); 
     } 

     // If this activity was started with an intent without an app widget ID, finish with an error. 
     if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { 
      finish(); 
      return; 
     } 

     mAppWidgetText.setText(loadTitlePref(NewAppWidgetConfigureActivity.this, mAppWidgetId)); 
    } 

    View.OnClickListener mOnClickListener = new View.OnClickListener() { 
     public void onClick(View v) { 
      final Context context = NewAppWidgetConfigureActivity.this; 

      // When the button is clicked, store the string locally 
      String widgetText = mAppWidgetText.getText().toString(); 
      saveTitlePref(context,mAppWidgetId,widgetText); 

      // It is the responsibility of the configuration activity to update the app widget 
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 
      NewAppWidget.updateAppWidget(context, appWidgetManager, mAppWidgetId); 

      // Make sure we pass back the original appWidgetId 
      Intent resultValue = new Intent(); 
      resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); 
      setResult(RESULT_OK, resultValue); 
      finish(); 
     } 
    }; 

    // Write the prefix to the SharedPreferences object for this widget 
    static void saveTitlePref(Context context, int appWidgetId, String text) { 
     SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); 
     prefs.putString(PREF_PREFIX_KEY + appWidgetId, text); 
     prefs.apply(); 
    } 

    // Read the prefix from the SharedPreferences object for this widget. 
    // If there is no preference saved, get the default from a resource 
    static String loadTitlePref(Context context, int appWidgetId) { 
     SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0); 
     String titleValue = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null); 
     if (titleValue != null) { 
      return titleValue; 
     } else { 
      return context.getString(R.string.appwidget_text); 
     } 
    } 

    static void deleteTitlePref(Context context, int appWidgetId) { 
     SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); 
     prefs.remove(PREF_PREFIX_KEY + appWidgetId); 
     prefs.apply(); 
    } 
} 

그리고 공급자 :

package com.example.desktop_win10.myapplication; 

import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.widget.RemoteViews; 

/** 
* Implementation of App Widget functionality. 
* App Widget Configuration implemented in {@link NewAppWidgetConfigureActivity NewAppWidgetConfigureActivity} 
*/ 
public class NewAppWidget extends AppWidgetProvider { 

    @Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
     // There may be multiple widgets active, so update all of them 
     for (int appWidgetId : appWidgetIds) { 
      updateAppWidget(context, appWidgetManager, appWidgetId); 
     } 
    } 

    @Override 
    public void onDeleted(Context context, int[] appWidgetIds) { 
     // When the user deletes the widget, delete the preference associated with it. 
     for (int appWidgetId : appWidgetIds) { 
      NewAppWidgetConfigureActivity.deleteTitlePref(context, appWidgetId); 
     } 
    } 

    @Override 
    public void onEnabled(Context context) { 
     // Enter relevant functionality for when the first widget is created 
    } 

    @Override 
    public void onDisabled(Context context) { 
     // Enter relevant functionality for when the last widget is disabled 
    } 

    static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, 
      int appWidgetId) { 

     CharSequence widgetText = NewAppWidgetConfigureActivity.loadTitlePref(context, appWidgetId); 
     // Construct the RemoteViews object 
     RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); 
     views.setTextViewText(R.id.appwidget_text, widgetText); 

     // Instruct the widget manager to update the widget 
     appWidgetManager.updateAppWidget(appWidgetId, views); 
    } 
} 
+0

'Default Activity not found .'는 매우 분명하게 문제입니다. 기본 의도를 추가 할 때 오류 란 무엇입니까? 또한 시간을 낭비해서 미안하지만 코드를 컴파일하는 방식이 IDE로 바뀌지 않습니다 –

+0

@ cricket_007 문제가 있습니다. 아무런 활동이없는 위젯 프로젝트이기 때문에 기본 활동이 없습니다. 공급자는 action intent-filter android.appwidget.action.APPWIDGET_CONFIGURE에 의해 유일한 하나 (구성 활동)를 시작해야합니다. – gegengift

답변

0

가 추가나요 :

<action android:name="android.intent.action.MAIN"/> 
<category android:name="android.intent.category.LAUNCHER" /> 

?

내가 아는 한, 안드로이드는 어떤 활동을 주 활동으로 시작할지 모릅니다.

+0

정확히는 아닙니다. 하지만 지금은 공급자 - doesn 작업을 시도합니다. 실행 구성에서 "아무것도 없음"을 선택할 수없는 이유는 무엇입니까? 그리고 구성 활동을 시작해야하는 android.appwidget.action.APPWIDGET_CONFIGURE를 선언하기 때문에 활동에서 잘못된 장소가됩니다. 이제 나는 그것을 활동에서 시험 해보기를 조급합니다 : 3 번의 시도 후에 그것은 지금까지 작동합니다 (드물게 작동합니다). – gegengift

+0

이제 응용 프로그램이 설치되었지만 콘솔에 다음과 같이 표시됩니다. 응용 프로그램이 온라인 상태가되기를 기다리는 중입니다. 편리한 쇼 : 디버거를 기다리는 중 ... Force ...? 활동이 시작되고 끝나는 시간을 조금 기다리십시오. 응용 프로그램이 설치되었지만 위젯이 설치되지 않았습니다. 나는 이유를 알지 못한다.하지만 이제 4 번의 시련 이후 위젯이 위젯 메뉴에있다. 하지만 홈 화면에 추가하면 디버거가 등록되지 않습니다. – gegengift

+0

"Invalidate and Clear Caches"를 사용하려고 했습니까? –

관련 문제