다른 휴대 전화 및 공급 업체는 다른 시계 앱을 가지고 있습니다. 일부 휴대 전화에서 앱을 여는 코드를 사용할 수 있습니다. 서로 다른 대답은 다른 목록과 전략을 제시하며, 종종 문제가 발생합니다.android : 위젯을 클릭하여 알람 또는 시계 앱을 엽니 다.
답변
위젯을 클릭 할 때 시계 응용 프로그램을 열 수있는 안정적인 방법입니다.
이 코드는 위젯을 클릭하여 알람 또는 탁상 시계 앱을 열 수있는 방법을 설명합니다. 다른 솔루션의 안정성 문제를 해결합니다. 공유 기본 설정을 사용하여 전력 절약을 향상시킵니다.
휴대 전화 용 앱을 찾는 코드는 onEnabled에 배치됩니다. 그런 다음 앱이 공유 환경 설정에 정보를 저장하여 업데이트 서비스에서 호출되도록합니다. 첫 번째 패키지가 발견되면 검색이 중지됩니다. 알람 및 탁상 시계를 모두 검색하려면 선호하는 옵션을 배열 목록에 올려 놓으십시오. 그것은 위젯이 업데이트 될 때마다이 검색을 수행하지 않고 전력을 보존합니다. 위젯이 자주 업데이트되면 배터리 수명이 달라집니다.
사용자가 알람 앱을 변경할 수 있다고 생각되면 onEnabled 코드를 WidgetProvider 클래스의 별도 메소드에 배치 할 수 있습니다. 그런 다음 onEnabled에서 호출하고 사용자 시계 패키지에서 변경 사항을 감지하면이를 호출합니다.
위젯 프로 바이더 클래스
공용 클래스 WidgetProvider는 시계 애플 리케이션의 배열은 몇 가지 일반적인 공급 업체를 포함, 완료되지 않았습니다의 AppWidgetProvider {
public static final String SHARED_PREFS = "SharedPrefs"; private PendingIntent pendingIntent = null; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // start UpdateService whenever onUpdate is called Intent sIntent = new Intent(context, UpdateService.class); sIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startService(sIntent); } @Override public void onEnabled(Context context) { super.onEnabled(context); Log.w(LOG, "WidgetProvider.onEnabled triggered"); // find the local alarm service // this is an incomplete array of alarm+clock services, // in an arbitrary order of priority. // you may need to change the order to suit your requirements String clockImpls[][] = { { "Standard Alarm", "com.android.alarmclock", "com.android.alarmclock.AlarmClock" }, { "Sony Alarm", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" }, { "Sony Ericsson Xperia Z", "com.sonyericsson.organizer", "com.sonyericsson.organizer.Organizer_WorldClock" }, { "ASUS Alarm Clock", "com.asus.alarmclock", "com.asus.alarmclock.AlarmClock" }, { "ASUS Desk Clock", "com.asus.deskclock", "com.asus.deskclock.DeskClock" }, { "HTC Alarm ClockDT", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, { "Standard Alarm ClockDT", "com.android.deskclock", "com.android.deskclock.AlarmClock" }, { "Froyo Nexus Alarm ClockDT", "com.google.android.deskclock", "com.android.deskclock.DeskClock" }, { "Moto Blur Alarm ClockDT", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock" }, { "Samsung Galaxy S", "com.sec.android.app.clockpackage", "com.sec.android.app.clockpackage.ClockPackage" } }; PackageManager packageManager = context.getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); boolean foundClockImpl = false; String vendorName = ""; String packageName = ""; String className = ""; for(int i=0; i<clockImpls.length; i++) { vendorName = clockImpls[i][0]; // not needed, for debugging only packageName = clockImpls[i][1]; className = clockImpls[i][2]; try { ComponentName cn = new ComponentName(packageName, className); packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); foundClockImpl = true; } catch (PackageManager.NameNotFoundException e) { // Log.w(LOG, "AlarmService couldnt retrieve activity info"); } if (foundClockImpl) { // when the first package is found // send alarmCLockIntent to Shared Preferences // and break out of the for loop SharedPreferences settings = context.getSharedPreferences(SHARED_PREFS, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString("VendorName", vendorName); // only needed for debugging editor.putString("PackageName", packageName); editor.putString("ClassName", className); // Commit the edits! editor.commit(); break; // stop searching to avoid setting less suitable options } } }
을 확장합니다. 이러한 앱이없는 기기가있을 것입니다. 주석에 다른 공급 업체의 응용 프로그램을 넣을 수 있으며 배열로 편집 할 것입니다. 나는 "System Tuner"앱을 사용하여 내 장치의 패키지 정보를 찾았다.
첫 번째 위젯을 배치하면 패키지 정보가 공유 환경 설정에 저장되었습니다. 그런 다음 UpdateService는이 정보를 호출하여 위젯이 업데이트 될 때마다 보류중인 인 텐트를 만듭니다. 권장 사항 : 업데이트 할 때마다 보류중인 모든 인 텐트 및 기타 원격 뷰 업데이트를 모두 업데이트하십시오. 이것은 다시 시작하거나 방향을 변경하는 방법에 발생하는 문제를 방지 할 수 등
업데이트 서비스 CLASS
공용 클래스 UpdateService 서비스를 확장 {
public static final String SHARED_PREFS = "SharedPrefs"; private PendingIntent pendingIntent = null; @Override public int onStartCommand(Intent intent, int flags, int startId) { // retrieve data from shared preferences SharedPreferences settings = getSharedPreferences(SHARED_PREFS, 0); // retrieve all your preferences each time, update everything int background = settings.getInt("Background", R.drawable.bg_box_light); // if cannot retrieve, set default to standard package // if it is not available, widget click will do nothing. String packageName = settings.getString("PackageName", "com.android.alarmclock"); String className = settings.getString("ClassName", "com.android.alarmclock.AlarmClock"); // get appwidgetmanager instance for all widgets AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this); // set up openAlarm PI PackageManager packageManager = this.getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); // construct pending intent from retrieved package info try { ComponentName cn = new ComponentName(packageName, className); packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); } catch (PackageManager.NameNotFoundException e) { // Log or debug message } PendingIntent alarmPI = PendingIntent.getActivity(this, 0, alarmClockIntent, 0); // update all widget instances ComponentName thisWidget = new ComponentName(getBaseContext(), WidgetProvider.class); int[] allWidgetIds = localAppWidgetManager.getAppWidgetIds(thisWidget); for (int widgetId : allWidgetIds) { RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout_name); // update EVERYTHING, EVERY TIME. // whatever is not updated may revert to the initial layout settings remoteViews.setImageViewResource(R.id.imageviewBG, background); remoteViews.setOnClickPendingIntent(R.id.analogClock, alarmPI); localAppWidgetManager.updateAppWidget(widgetId, remoteViews); }
가 두 개 이상있는 경우 위젯 공급자를 사용하는 경우 각 공급자마다 //update all widget instances
에서 시작하는 코드를 복제하고 widget_layout_name을 변경하십시오. 이 코드는 동일한 방식으로 모든 다른 위젯 레이아웃을 업데이트합니다. 다른 위젯 레이아웃이 다른 환경 설정을 허용하려면 코드를 변경하여 각 위젯 레이아웃에 대한 고유 식별자를 만들고 각 레이아웃에 대한 공유 환경 설정 집합을 작성하십시오.
- 1. 클릭하여 div를 엽니 다.
- 2. Android - 알람 시계 오류
- 3. Android 알람 시계
- 4. 링크를 클릭하여 Datepicker를 엽니 다.
- 5. 버튼을 클릭하여 양식을 엽니 다.
- 6. .mp3 링크를 클릭하면 Android 앱을 엽니 다.
- 7. Android 알람 시계 방송/감지
- 8. 여러 알람이있는 Android 알람 시계
- 9. android의 twitter 앱에서 트윗을 클릭하여 앱을 엽니 다.
- 10. Mac 용 알람 시계 앱을 내 놓습니다
- 11. 알람 시계 설정
- 12. UIButton으로 다른 앱을 엽니 다.
- 13. 배경에서 iOS 앱을 엽니 다.
- 14. iOS의 알람 시계 앱
- 15. MGWT (gwt-phonegap) 앱에서 외부 Android 앱을 엽니 다.
- 16. objective-c에서 파일을 더블 클릭하여 엽니 다.
- 17. Cordova 알람 시계
- 18. iOS 알람 시계
- 19. 버튼을 클릭하여 선택 옵션 목록을 엽니 다.
- 20. Google지도를 클릭하여 새 창에서 링크를 엽니 다.
- 21. 블렌더 개체를 클릭하여 하이퍼 링크를 엽니 다.
- 22. 메뉴 버튼을 클릭하여 웹 사이트를 엽니 다.
- 23. recyclerview 항목을 클릭하여 Fragment를 엽니 다.
- 24. JCalendar 일을 클릭하여 새 JFrame을 엽니 다.
- 25. 더블 클릭하여 ckeditor 대화 상자를 엽니 다.
- 26. Strange ToolStripButton OpenFileDialog 비헤이비어를 클릭하여 엽니 다.
- 27. 지도에서 마커를 클릭하여 대화 상자를 엽니 다.
- 28. thunbnail 아이콘이있는 카메라 앱을 엽니 다.
- 29. WebView 앱이 YouTube 앱을 엽니 다.
- 30. AngularJS 타이머 알람 시계