launch https://www.e-learn.cn/tag/launch zh-hans how to open a 'csv file' like 'url launcher' in Flutter https://www.e-learn.cn/topic/4090837 <span>how to open a &#039;csv file&#039; like &#039;url launcher&#039; in Flutter</span> <span><span lang="" about="/user/120" typeof="schema:Person" property="schema:name" datatype="">て烟熏妆下的殇ゞ</span></span> <span>2021-02-10 18:29:38</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>i converted list into File of .csv extension then tried <strong>OpenFile.open</strong> and ended up with error <code>No permissions found in manifest for: 2</code>, tried <strong>canLaunch</strong> and ended up with error <code>name.csv exposed beyond app through Intent.getData(), Failed to handle method call</code></p> <p>so how to open that csv file in any 3rd part application.</p> <br /><h3>回答1:</h3><br /><p>You can copy paste run full code below <br /> and make sure you have a file <code>/sdcard/Download/sample.csv</code>, see picture below <br /> You also need CSV Viewer installed in your Emulator <br /> code snippet</p> <pre><code> final filePath = '/sdcard/Download/sample.csv'; print('${filePath}'); final message = await OpenFile.open(filePath); </code></pre> <p>working demo</p> <p></p> <p>device file explorer</p> <p></p> <p>full code</p> <pre><code>import 'package:flutter/material.dart'; import 'dart:async'; import 'package:open_file/open_file.dart'; void main() =&gt; runApp(new MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() =&gt; new _MyAppState(); } class _MyAppState extends State&lt;MyApp&gt; { String _openResult = 'Unknown'; Future&lt;void&gt; openFile() async { //final filePath = '/sdcard/Download/sample.pdf'; final filePath = '/sdcard/Download/sample.csv'; print('${filePath}'); final message = await OpenFile.open(filePath); setState(() { _openResult = message; }); } @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( appBar: new AppBar( title: const Text('Plugin example app'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: &lt;Widget&gt;[ Text('open result: $_openResult\n'), FlatButton( child: Text('Tap to open file'), onPressed: openFile, ), ], ), ), ), ); } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/59053056/how-to-open-a-csv-file-like-url-launcher-in-flutter</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/csv" hreflang="zh-hans">csv</a></div> <div class="field--item"><a href="/tag/flutter" hreflang="zh-hans">Flutter</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Wed, 10 Feb 2021 10:29:38 +0000 て烟熏妆下的殇ゞ 4090837 at https://www.e-learn.cn how to open a 'csv file' like 'url launcher' in Flutter https://www.e-learn.cn/topic/4090831 <span>how to open a &#039;csv file&#039; like &#039;url launcher&#039; in Flutter</span> <span><span lang="" about="/user/60" typeof="schema:Person" property="schema:name" datatype="">ぐ巨炮叔叔</span></span> <span>2021-02-10 18:29:24</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>i converted list into File of .csv extension then tried <strong>OpenFile.open</strong> and ended up with error <code>No permissions found in manifest for: 2</code>, tried <strong>canLaunch</strong> and ended up with error <code>name.csv exposed beyond app through Intent.getData(), Failed to handle method call</code></p> <p>so how to open that csv file in any 3rd part application.</p> <br /><h3>回答1:</h3><br /><p>You can copy paste run full code below <br /> and make sure you have a file <code>/sdcard/Download/sample.csv</code>, see picture below <br /> You also need CSV Viewer installed in your Emulator <br /> code snippet</p> <pre><code> final filePath = '/sdcard/Download/sample.csv'; print('${filePath}'); final message = await OpenFile.open(filePath); </code></pre> <p>working demo</p> <p></p> <p>device file explorer</p> <p></p> <p>full code</p> <pre><code>import 'package:flutter/material.dart'; import 'dart:async'; import 'package:open_file/open_file.dart'; void main() =&gt; runApp(new MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() =&gt; new _MyAppState(); } class _MyAppState extends State&lt;MyApp&gt; { String _openResult = 'Unknown'; Future&lt;void&gt; openFile() async { //final filePath = '/sdcard/Download/sample.pdf'; final filePath = '/sdcard/Download/sample.csv'; print('${filePath}'); final message = await OpenFile.open(filePath); setState(() { _openResult = message; }); } @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( appBar: new AppBar( title: const Text('Plugin example app'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: &lt;Widget&gt;[ Text('open result: $_openResult\n'), FlatButton( child: Text('Tap to open file'), onPressed: openFile, ), ], ), ), ), ); } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/59053056/how-to-open-a-csv-file-like-url-launcher-in-flutter</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/csv" hreflang="zh-hans">csv</a></div> <div class="field--item"><a href="/tag/flutter" hreflang="zh-hans">Flutter</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Wed, 10 Feb 2021 10:29:24 +0000 ぐ巨炮叔叔 4090831 at https://www.e-learn.cn Determine when application icon is clicked to launch the app in android https://www.e-learn.cn/topic/4072786 <span>Determine when application icon is clicked to launch the app in android</span> <span><span lang="" about="/user/16" typeof="schema:Person" property="schema:name" datatype="">筅森魡賤</span></span> <span>2021-02-08 03:36:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Is there any way in android to determine when the user clicked the app icon to launch the app ? I mean say a user was using my app. Then he presses the home key as a result of which the app goes to the background. After sometime he clicks the app icon again. My question is do I get a call-back for this ?</p> <br /><h3>回答1:</h3><br /><p>Just to inform, I used the flag <code>android:clearTaskOnLaunch="true"</code> in my launcher activity. As a result, its onResume method was called and I could identify that the launcher icon was clicked</p> <br /><br /><br /><h3>回答2:</h3><br /><p>It will call the onResume() method if the app is already in the stack. And if the app not in the stack then it will call the onCreate() method.</p> <p>This mechanism is based on the launchMode specified for the activity.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>please read http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle</p> <p>How many activities your application has, you will get a callback <code>onResume()</code> for the last open activity.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/2786160/determine-when-application-icon-is-clicked-to-launch-the-app-in-android</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Sun, 07 Feb 2021 19:36:26 +0000 筅森魡賤 4072786 at https://www.e-learn.cn How to leave the current app and launch an activity of another app? https://www.e-learn.cn/topic/4037268 <span>How to leave the current app and launch an activity of another app?</span> <span><span lang="" about="/user/226" typeof="schema:Person" property="schema:name" datatype="">泄露秘密</span></span> <span>2021-01-29 09:03:08</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have a simple Android app that needs to launch another app under certain condition, and I will need to check the condition upon the app launch. That is, either continue to launch my app or just launch another app:</p> <pre><code>if (A == true) { launch another activity of another app leave the current app without creating the main activity } else { launch the main activity of the current app } </code></pre> <p>Could anyone please let me know how to deal with A == true case? I am able to launch another app's activity but I have trouble leaving the current app without even opening the main activity.</p> <p>Any help will be greatly appreciated!</p> <br /><h3>回答1:</h3><br /><p>You can launch other application using following intent</p> <pre><code>Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");//pass the packagename of app you want to open startActivity( LaunchIntent ); </code></pre> <p>If you don't know the package name of application that you wanted to launch then try your hand on</p> <pre><code>PackageManager pm; pm = getPackageManager(); // get a list of installed apps. packages = pm.getInstalledApplications(0); </code></pre> <p>Pass the packagename of app you want to open You can use this if A == true</p> <p>else You can launch the MainActivity as</p> <pre><code>startActivity(new Intent(CurrentActivity.this,MainActivity.class)); </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>If you want to start another activity of another app without the normal IntentFilter then the easiest solutions is:</p> <pre><code>Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName("com.anotherapp.package","com.anotherapp.package.MainActivity")); startActivity(intent); </code></pre> <p>Of course, you would <strong>need to know</strong> the <code>package name</code> and the <code>Activity</code> name you want to start</p> <p>As for finishing your application call</p> <pre><code>finishAndRemoveTask(); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/50017762/how-to-leave-the-current-app-and-launch-an-activity-of-another-app</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/android-activity" hreflang="zh-hans">android-activity</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Fri, 29 Jan 2021 01:03:08 +0000 泄露秘密 4037268 at https://www.e-learn.cn WatchOS3 Complication that launches App https://www.e-learn.cn/topic/3975618 <span>WatchOS3 Complication that launches App</span> <span><span lang="" about="/user/56" typeof="schema:Person" property="schema:name" datatype="">杀马特。学长 韩版系。学妹</span></span> <span>2020-12-24 14:27:53</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I would like to create a complication for watchOS 3 that will simply launch my App. I have used XCode to create the ComplicationController:</p> <pre><code>class ComplicationController: NSObject, CLKComplicationDataSource { // MARK: - Timeline Configuration func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { handler([.forward, .backward]) } func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -&gt; Void) { handler(nil) } func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -&gt; Void) { handler(nil) } func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -&gt; Void) { handler(.showOnLockScreen) } // MARK: - Timeline Population func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { // Call the handler with the current timeline entry handler(nil) } func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -&gt; Void) { // Call the handler with the timeline entries prior to the given date handler(nil) } func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -&gt; Void) { // Call the handler with the timeline entries after to the given date handler(nil) } // MARK: - Placeholder Templates func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached handler(nil) } } </code></pre> <p>and added images for the Circular, Modular and Utilitarian assets. But when I run the Watch App I cannot select my complications for a Watch face. What do I still need to do?</p> <p>Thanks</p> <p>Greg</p> <br /><h3>回答1:</h3><br /><p>These code changes are required:</p> <pre><code>func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { handler([]) } func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { if complication.family == .circularSmall { let template = CLKComplicationTemplateCircularSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Circular")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else if complication.family == .utilitarianSmall { let template = CLKComplicationTemplateUtilitarianSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Utilitarian")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else if complication.family == .modularSmall { let template = CLKComplicationTemplateModularSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Modular")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { switch complication.family { case .circularSmall: let image: UIImage = UIImage(named: "Circular")! let template = CLKComplicationTemplateCircularSmallSimpleImage() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) case .utilitarianSmall: let image: UIImage = UIImage(named: "Utilitarian")! let template = CLKComplicationTemplateUtilitarianSmallSquare() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) case .modularSmall: let image: UIImage = UIImage(named: "Modular")! let template = CLKComplicationTemplateModularSmallSimpleImage() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) default: handler(nil) } } </code></pre> <p>Plus you need to provide the images as assets in the extension.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Apple Watch 4 new graphic complications looks like this:</p> <pre><code>func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { // Call the handler with the current timeline entry switch complication.family { case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() let image = UIImage(named: "Complication/Graphic Corner")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } case .graphicCircular: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCircularImage() let image = UIImage(named: "Complication/Graphic Circular")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } default: handler(nil) } } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached switch complication.family { case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() let image = UIImage(named: "Complication/Graphic Corner")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) handler(template) } else { handler(nil) } case .graphicCircular: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCircularImage() let image = UIImage(named: "Complication/Graphic Circular")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) handler(template) } else { handler(nil) } default: handler(nil) } } </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Add Apple Watch 4 new graphic complications (watchOS 5.0+) and <strong>prevent crash</strong> on Apple Watch Series 1, 2 and 3.</p> <p>Important: the code from Zoltan will crash on Apple Watch series 3 or lower.</p> <p>According to the Apple documentation, the new graphic complications require watchOS 5.0 or higher <strong>and</strong> a Watch Series 4 or later:</p> <blockquote> <p><strong>Note</strong> Watch faces that support graphic templates are available only on Apple Watch Series 4 or later.</p> </blockquote> <p>This means that a Watch Series 3 with watchOS 5 or 6 (due to <code>if #available(watchOSApplicationExtension 5.0, *)</code>) will attempt to load the complication image from the asset catalogue. However, since App Thinning is enabled by default, the Watch Series 3 doesn't have the image in it's binary and therefor the following line will <strong>crash</strong> the app:</p> <p><code>let image = UIImage(named: "Complication/Graphic Corner")!</code></p> <p>We discovered this when we found thousands of crash reports in Xcode:</p> <ol><li>Open Xcode</li> <li>Window -&gt; Organizer</li> <li>Select tab "Crashes"</li> <li>Select an App Store version</li> </ol><p>We found a crash report for each of the 2 Graphic complications that we support, all were with watchOS 5 or 6 and Watch Series 2 or 3, like:</p> <p></p> <p><strong>Solution</strong></p> <p>Embed loading of the graphic asset within an IF statement and return <code>nil</code> as template, so it won't crash on devices without the asset.</p> <p>The example above from Zoltan will be:</p> <pre><code>case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() if let image = UIImage(named: "Complication/Graphic Corner") { template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } } else { handler(nil) } </code></pre> <p>For efficient and maintainable code, we created a reusable function <code>templateForComplication()</code> that is used in all 3 mandatory delegate functions:</p> <pre class="lang-swift prettyprint-override"><code>class ComplicationController: NSObject, CLKComplicationDataSource { // MARK: Mandatory Delegate Methods func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { // Turn off time travelling: handler([]) } func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { let template = templateForComplication(complication: complication) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template!) handler(timelineEntry) } func getPlaceholderTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached handler(templateForComplication(complication: complication)) } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { handler(templateForComplication(complication: complication)) } // MARK: Helper Methods private func templateForComplication(complication: CLKComplication) -&gt; CLKComplicationTemplate? { // Init default output: var template: CLKComplicationTemplate? = nil // Graphic Complications are only availably since watchOS 5.0: if #available(watchOSApplicationExtension 5.0, *) { // NOTE: Watch faces that support graphic templates are available only on Apple Watch Series 4 or later. So the binary on older devices (e.g. Watch Series 3) will not contain the images. if complication.family == .graphicCircular { let imageTemplate = CLKComplicationTemplateGraphicCircularImage() // Check if asset exists, to prevent crash on non-supported devices: if let fullColorImage = UIImage(named: "Complication/Graphic Circular") { let imageProvider = CLKFullColorImageProvider.init(fullColorImage: fullColorImage) imageTemplate.imageProvider = imageProvider template = imageTemplate } } else if complication.family == .graphicCorner { let imageTemplate = CLKComplicationTemplateGraphicCornerCircularImage() // Check if asset exists, to prevent crash on non-supported devices: if let fullColorImage = UIImage(named: "Complication/Graphic Corner") { let imageProvider = CLKFullColorImageProvider.init(fullColorImage: fullColorImage) imageTemplate.imageProvider = imageProvider template = imageTemplate } } } // For all watchOS versions: if complication.family == .circularSmall { let imageTemplate = CLKComplicationTemplateCircularSmallSimpleImage() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Circular")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } else if complication.family == .modularSmall { let imageTemplate = CLKComplicationTemplateModularSmallSimpleImage() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Modular")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } else if complication.family == .utilitarianSmall { let imageTemplate = CLKComplicationTemplateUtilitarianSmallSquare() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Utilitarian")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } return template } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/39708407/watchos3-complication-that-launches-app</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/swift" hreflang="zh-hans">swift</a></div> <div class="field--item"><a href="/tag/watchkit" hreflang="zh-hans">watchkit</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> <div class="field--item"><a href="/tag/apple-watch-complication" hreflang="zh-hans">apple-watch-complication</a></div> <div class="field--item"><a href="/tag/watchos-3" hreflang="zh-hans">watchos-3</a></div> </div> </div> Thu, 24 Dec 2020 06:27:53 +0000 杀马特。学长 韩版系。学妹 3975618 at https://www.e-learn.cn WatchOS3 Complication that launches App https://www.e-learn.cn/topic/3975617 <span>WatchOS3 Complication that launches App</span> <span><span lang="" about="/user/242" typeof="schema:Person" property="schema:name" datatype="">拟墨画扇</span></span> <span>2020-12-24 14:27:21</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I would like to create a complication for watchOS 3 that will simply launch my App. I have used XCode to create the ComplicationController:</p> <pre><code>class ComplicationController: NSObject, CLKComplicationDataSource { // MARK: - Timeline Configuration func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { handler([.forward, .backward]) } func getTimelineStartDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -&gt; Void) { handler(nil) } func getTimelineEndDate(for complication: CLKComplication, withHandler handler: @escaping (Date?) -&gt; Void) { handler(nil) } func getPrivacyBehavior(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationPrivacyBehavior) -&gt; Void) { handler(.showOnLockScreen) } // MARK: - Timeline Population func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { // Call the handler with the current timeline entry handler(nil) } func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -&gt; Void) { // Call the handler with the timeline entries prior to the given date handler(nil) } func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -&gt; Void) { // Call the handler with the timeline entries after to the given date handler(nil) } // MARK: - Placeholder Templates func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached handler(nil) } } </code></pre> <p>and added images for the Circular, Modular and Utilitarian assets. But when I run the Watch App I cannot select my complications for a Watch face. What do I still need to do?</p> <p>Thanks</p> <p>Greg</p> <br /><h3>回答1:</h3><br /><p>These code changes are required:</p> <pre><code>func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { handler([]) } func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { if complication.family == .circularSmall { let template = CLKComplicationTemplateCircularSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Circular")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else if complication.family == .utilitarianSmall { let template = CLKComplicationTemplateUtilitarianSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Utilitarian")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else if complication.family == .modularSmall { let template = CLKComplicationTemplateModularSmallRingImage() template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Modular")!) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { switch complication.family { case .circularSmall: let image: UIImage = UIImage(named: "Circular")! let template = CLKComplicationTemplateCircularSmallSimpleImage() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) case .utilitarianSmall: let image: UIImage = UIImage(named: "Utilitarian")! let template = CLKComplicationTemplateUtilitarianSmallSquare() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) case .modularSmall: let image: UIImage = UIImage(named: "Modular")! let template = CLKComplicationTemplateModularSmallSimpleImage() template.imageProvider = CLKImageProvider(onePieceImage: image) handler(template) default: handler(nil) } } </code></pre> <p>Plus you need to provide the images as assets in the extension.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Apple Watch 4 new graphic complications looks like this:</p> <pre><code>func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { // Call the handler with the current timeline entry switch complication.family { case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() let image = UIImage(named: "Complication/Graphic Corner")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } case .graphicCircular: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCircularImage() let image = UIImage(named: "Complication/Graphic Circular")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } default: handler(nil) } } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached switch complication.family { case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() let image = UIImage(named: "Complication/Graphic Corner")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) handler(template) } else { handler(nil) } case .graphicCircular: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCircularImage() let image = UIImage(named: "Complication/Graphic Circular")! template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) handler(template) } else { handler(nil) } default: handler(nil) } } </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Add Apple Watch 4 new graphic complications (watchOS 5.0+) and <strong>prevent crash</strong> on Apple Watch Series 1, 2 and 3.</p> <p>Important: the code from Zoltan will crash on Apple Watch series 3 or lower.</p> <p>According to the Apple documentation, the new graphic complications require watchOS 5.0 or higher <strong>and</strong> a Watch Series 4 or later:</p> <blockquote> <p><strong>Note</strong> Watch faces that support graphic templates are available only on Apple Watch Series 4 or later.</p> </blockquote> <p>This means that a Watch Series 3 with watchOS 5 or 6 (due to <code>if #available(watchOSApplicationExtension 5.0, *)</code>) will attempt to load the complication image from the asset catalogue. However, since App Thinning is enabled by default, the Watch Series 3 doesn't have the image in it's binary and therefor the following line will <strong>crash</strong> the app:</p> <p><code>let image = UIImage(named: "Complication/Graphic Corner")!</code></p> <p>We discovered this when we found thousands of crash reports in Xcode:</p> <ol><li>Open Xcode</li> <li>Window -&gt; Organizer</li> <li>Select tab "Crashes"</li> <li>Select an App Store version</li> </ol><p>We found a crash report for each of the 2 Graphic complications that we support, all were with watchOS 5 or 6 and Watch Series 2 or 3, like:</p> <p></p> <p><strong>Solution</strong></p> <p>Embed loading of the graphic asset within an IF statement and return <code>nil</code> as template, so it won't crash on devices without the asset.</p> <p>The example above from Zoltan will be:</p> <pre><code>case .graphicCorner: if #available(watchOSApplicationExtension 5.0, *) { let template = CLKComplicationTemplateGraphicCornerCircularImage() if let image = UIImage(named: "Complication/Graphic Corner") { template.imageProvider = CLKFullColorImageProvider(fullColorImage: image) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template) handler(timelineEntry) } else { handler(nil) } } else { handler(nil) } </code></pre> <p>For efficient and maintainable code, we created a reusable function <code>templateForComplication()</code> that is used in all 3 mandatory delegate functions:</p> <pre class="lang-swift prettyprint-override"><code>class ComplicationController: NSObject, CLKComplicationDataSource { // MARK: Mandatory Delegate Methods func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -&gt; Void) { // Turn off time travelling: handler([]) } func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -&gt; Void) { let template = templateForComplication(complication: complication) let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template!) handler(timelineEntry) } func getPlaceholderTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { // This method will be called once per supported complication, and the results will be cached handler(templateForComplication(complication: complication)) } func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -&gt; Void) { handler(templateForComplication(complication: complication)) } // MARK: Helper Methods private func templateForComplication(complication: CLKComplication) -&gt; CLKComplicationTemplate? { // Init default output: var template: CLKComplicationTemplate? = nil // Graphic Complications are only availably since watchOS 5.0: if #available(watchOSApplicationExtension 5.0, *) { // NOTE: Watch faces that support graphic templates are available only on Apple Watch Series 4 or later. So the binary on older devices (e.g. Watch Series 3) will not contain the images. if complication.family == .graphicCircular { let imageTemplate = CLKComplicationTemplateGraphicCircularImage() // Check if asset exists, to prevent crash on non-supported devices: if let fullColorImage = UIImage(named: "Complication/Graphic Circular") { let imageProvider = CLKFullColorImageProvider.init(fullColorImage: fullColorImage) imageTemplate.imageProvider = imageProvider template = imageTemplate } } else if complication.family == .graphicCorner { let imageTemplate = CLKComplicationTemplateGraphicCornerCircularImage() // Check if asset exists, to prevent crash on non-supported devices: if let fullColorImage = UIImage(named: "Complication/Graphic Corner") { let imageProvider = CLKFullColorImageProvider.init(fullColorImage: fullColorImage) imageTemplate.imageProvider = imageProvider template = imageTemplate } } } // For all watchOS versions: if complication.family == .circularSmall { let imageTemplate = CLKComplicationTemplateCircularSmallSimpleImage() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Circular")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } else if complication.family == .modularSmall { let imageTemplate = CLKComplicationTemplateModularSmallSimpleImage() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Modular")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } else if complication.family == .utilitarianSmall { let imageTemplate = CLKComplicationTemplateUtilitarianSmallSquare() let imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Utilitarian")!) imageProvider.tintColor = UIColor.blue imageTemplate.imageProvider = imageProvider template = imageTemplate } return template } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/39708407/watchos3-complication-that-launches-app</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/swift" hreflang="zh-hans">swift</a></div> <div class="field--item"><a href="/tag/watchkit" hreflang="zh-hans">watchkit</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> <div class="field--item"><a href="/tag/apple-watch-complication" hreflang="zh-hans">apple-watch-complication</a></div> <div class="field--item"><a href="/tag/watchos-3" hreflang="zh-hans">watchos-3</a></div> </div> </div> Thu, 24 Dec 2020 06:27:21 +0000 拟墨画扇 3975617 at https://www.e-learn.cn Android 10.0 Application startup on BOOT https://www.e-learn.cn/topic/3955761 <span>Android 10.0 Application startup on BOOT</span> <span><span lang="" about="/user/33" typeof="schema:Person" property="schema:name" datatype="">被刻印的时光 ゝ</span></span> <span>2020-12-08 02:07:22</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We have an android application which we intend to start/launch during phone boot. With some code tries in Android 10, we realized that the launching of app on boot, is not possible after Android 8.0. Previously in Android 6, it was possible. Even in physical device /phone / emulator Android 10 , we gave permission in AutoStart list our application. &lt;&lt; Objective: Any way (workaround) to launch app on boot even on latest versions , i.e. Android 8 onwards ? &gt;&gt;</p> <p>Tries that we made in Android 10: following are 3 sections of code - AndroidManifest.xml, MyActivity.java, MyBroadcastReceiver.java</p> <p>1)AndroidManifest.xml</p> <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;&lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt; &lt;activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN"/&gt; &lt;category android:name="android.intent.category.LAUNCHER"/&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>2)MyActivity.java</p> <pre><code>public class MainActivity extends FlutterActivity { @java.lang.Override protected void onCreate(android.os.Bundle savedInstanceState) { super.onCreate(savedInstanceState); // "Display pop up window" if (!Settings.canDrawOverlays(getApplicationContext())) { startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)); } Log.d(TAG, "-------- onCreate -------"); // this is printed } } </code></pre> <p>3)MyBroadcastReceiver.java</p> <pre><code>public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Intent i = new Intent(context, MainActivity.class); i.setAction(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(i); Log.d(TAG, "------ tried to launch MainActivity -------"); // this is printed } } } </code></pre> <br /><h3>回答1:</h3><br /><p>Starting the app on boot can be annoying to the user. You can start a Foreground Service instead. The BOOT_COMPLETE intent can be in many different form depending on your device. I have tried to capture all of them here.</p> <p>In your Manifest:</p> <pre><code>&lt;receiver android:name=".receiver.BootReceiver" // YOUR RECEIVER HERE android:enabled="true" android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"&gt; &lt;intent-filter&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;action android:name="android.intent.action.ACTION_BOOT_COMPLETED" /&gt; &lt;action android:name="android.intent.action.REBOOT" /&gt; &lt;action android:name="android.intent.action.QUICKBOOT_POWERON" /&gt; &lt;action android:name="com.htc.intent.action.QUICKBOOT_POWERON" /&gt; &lt;action android:name="android.intent.action.ACTION_SHUTDOWN" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>And in the receiver:</p> <pre><code>class BootReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { // START FOREGROUND SERVICE HERE } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/64642362/android-10-0-application-startup-on-boot</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/boot" hreflang="zh-hans">boot</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Mon, 07 Dec 2020 18:07:22 +0000 被刻印的时光 ゝ 3955761 at https://www.e-learn.cn Can I select per-language debug configurations in VS Code? https://www.e-learn.cn/topic/3885362 <span>Can I select per-language debug configurations in VS Code?</span> <span><span lang="" about="/user/183" typeof="schema:Person" property="schema:name" datatype="">北城余情</span></span> <span>2020-10-28 05:00:28</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/64441752/can-i-select-per-language-debug-configurations-in-vs-code</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/debugging" hreflang="zh-hans">debugging</a></div> <div class="field--item"><a href="/tag/visual-studio-code-0" hreflang="zh-hans">visual-studio-code</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Tue, 27 Oct 2020 21:00:28 +0000 北城余情 3885362 at https://www.e-learn.cn Can I select per-language debug configurations in VS Code? https://www.e-learn.cn/topic/3885358 <span>Can I select per-language debug configurations in VS Code?</span> <span><span lang="" about="/user/84" typeof="schema:Person" property="schema:name" datatype="">混江龙づ霸主</span></span> <span>2020-10-28 04:59:47</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/64441752/can-i-select-per-language-debug-configurations-in-vs-code</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/debugging" hreflang="zh-hans">debugging</a></div> <div class="field--item"><a href="/tag/visual-studio-code-0" hreflang="zh-hans">visual-studio-code</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> </div> </div> Tue, 27 Oct 2020 20:59:47 +0000 混江龙づ霸主 3885358 at https://www.e-learn.cn Windows terminal: open multiple panes and execute specified command https://www.e-learn.cn/topic/3789416 <span>Windows terminal: open multiple panes and execute specified command</span> <span><span lang="" about="/user/108" typeof="schema:Person" property="schema:name" datatype="">青春壹個敷衍的年華</span></span> <span>2020-08-28 00:51:27</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>来源:<code>https://stackoverflow.com/questions/62468029/windows-terminal-open-multiple-panes-and-execute-specified-command</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/command" hreflang="zh-hans">command</a></div> <div class="field--item"><a href="/tag/execute" hreflang="zh-hans">execute</a></div> <div class="field--item"><a href="/tag/launch" hreflang="zh-hans">launch</a></div> <div class="field--item"><a href="/tag/pane" hreflang="zh-hans">pane</a></div> <div class="field--item"><a href="/tag/windows-terminal" hreflang="zh-hans">windows-terminal</a></div> </div> </div> Thu, 27 Aug 2020 16:51:27 +0000 青春壹個敷衍的年華 3789416 at https://www.e-learn.cn