<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>how to use Android DFU Library?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63055/how-to-use-android-dfu-library</link><description>Hi I am now aiming to progress ota with android application. Following the guidelines on ithub, I created a class DfuService, NotificationActivity. The class internal code has not been modified. It works when the button is pressed as shown below. But</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 29 Jun 2020 09:04:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63055/how-to-use-android-dfu-library" /><item><title>RE: how to use Android DFU Library?</title><link>https://devzone.nordicsemi.com/thread/257301?ContentTypeID=1</link><pubDate>Mon, 29 Jun 2020 09:04:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d3cd0b7-db61-402b-9e71-d0b3986920d4</guid><dc:creator>Serobegi</dc:creator><description>&lt;p&gt;&lt;span&gt;I checked the nRF Toolbox, but there are too many functions different from how to use the library. I only want to&amp;#39;OTA&amp;#39; one Zip file. Is there any easy way? I think I followed the DFU Library exactly, but it&amp;#39;s too hard to work.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It has a structure that calls OTA activity from Main and returns to Main when completed. Can you tell me where the problem in my code is? I&amp;#39;m challenging OTA for the second week... and I&amp;#39;m staying in the same place every day. Please ask for confirmation once, and thank you for the reply.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="java"&gt;otaStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final DfuServiceInitiator starter = new DfuServiceInitiator(SwitchDeviceMac)
                        .setDeviceName(SwitchDeviceName)
                        .setKeepBond(false)
                        .setForceDfu(false)
                        .setPacketsReceiptNotificationsEnabled(Build.VERSION.SDK_INT &amp;lt; Build.VERSION_CODES.M)
                        .setPacketsReceiptNotificationsValue(DfuServiceInitiator.DEFAULT_PRN_VALUE)
                        .setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)
                        .setPrepareDataObjectDelay(300L);

                final File root = new File(Environment.getExternalStorageDirectory(), &amp;quot;Nordic&amp;quot;);
                final File file = new File(root, &amp;quot;FILE&amp;quot;);

                starter.setZip(file.getPath());
                final DfuServiceController controller = starter.start(OTA.this, DfuService.class);
            }
        });
        
        
        ....
        
        
        import android.app.Activity;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;

import no.nordicsemi.android.dfu.BuildConfig;
import no.nordicsemi.android.dfu.DfuBaseService;

public class DfuService extends DfuBaseService {

    @Override
    protected Class&amp;lt;? extends Activity&amp;gt; getNotificationTarget() {
        /*
         * As a target activity the NotificationActivity is returned, not the MainActivity. This is because
         * the notification must create a new task:
         *
         * intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         *
         * when you press it. You can use NotificationActivity to check whether the new activity
         * is a root activity (that means no other activity was open earlier) or that some
         * other activity is already open. In the latter case the NotificationActivity will just be
         * closed. The system will restore the previous activity. However, if the application has been
         * closed during upload and you click the notification, a NotificationActivity will
         * be launched as a root activity. It will create and start the main activity and
         * terminate itself.
         *
         * This method may be used to restore the target activity in case the application
         * was closed or is open. It may also be used to recreate an activity history using
         * startActivities(...).
         */
        return NotificationActivity.class;
    }

    @Override
    protected boolean isDebug() {
        // Here return true if you want the service to print more logs in LogCat.
        // Library&amp;#39;s BuildConfig in current version of Android Studio is always set to DEBUG=false, so
        // make sure you return true or your.app.BuildConfig.DEBUG here.
        return BuildConfig.DEBUG;
    }

    @Override
    protected void updateForegroundNotification(@NonNull final NotificationCompat.Builder builder) {
        // Customize the foreground service notification here.
    }
}


....

package com.example.divide_scan_adver.Nordic;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.example.divide_scan_adver.MainActivity;

public class NotificationActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // If this activity is the root activity of the task, the app is not running
        if (isTaskRoot()) {
            // Start the app before finishing
            final Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtras(getIntent().getExtras()); // copy all extras
            startActivity(intent);
        }

        // Now finish, which will drop you to the activity at which you were at the top of the task stack
        finish();
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to use Android DFU Library?</title><link>https://devzone.nordicsemi.com/thread/257149?ContentTypeID=1</link><pubDate>Fri, 26 Jun 2020 12:57:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c5a5638-001e-411b-b299-6d27f28f7bb7</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am not sure if you are aware, but we have an application that is called &amp;quot;nRF Toolbox&amp;quot;. It is described &lt;a href="https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Toolbox" rel="noopener noreferrer" target="_blank"&gt;here&lt;/a&gt;, and that also contains a link to the Github with the source code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;nRF Toolbox has a module dedicated for DFU, so perhaps you can check the implementation on Github and use this as a starting point, and to see how it is used.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>