This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

what is NotificationActivity ?

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 parentIntent = new Intent(this, FeaturesActivity.class);
parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final Intent startAppIntent = new Intent(this, DfuActivity.class);
startAppIntent.putExtras(getIntent().getExtras());
startActivities(new Intent[] { parentIntent, startAppIntent });
}

// Now finish, which will drop the user in to the activity that was at the top
// of the task stack
finish();
}
}


The code above is the sample code provided by GitHub.
But I don't use what is called FeaturesActivity. So what class should I put there?
Below is my code. How would you like to modify it?

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, OTA.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();
}
}





  • Hello,

    The code above is the sample code provided by GitHub.
    But I don't use what is called FeaturesActivity. So what class should I put there?
    Below is my code. How would you like to modify it?

    Have you seen the notificationActivity's description in the Android DFU Library documentation?
    Furthermore, could you elaborate on what you would like the application to do - why are you changing this part - what is the desired behavior from the code you have written in place of the original code?

    Looking forward to resolving this issue together,

    Best regards,
    Karl

  • Thanks for the answer.

    FeaturesActivity was created by referring to Toolbox github.

    My goal is to simply OTA a specified file in a set directory.

    The code has been modified in the last two days and is written as follows. But still, I am not sure why NotificationActivity is used. What should the class call by Intent of NotificationActivity class contain?

    The program I am writing is performed by starting MainActivity -> OTA Activity is called -> Work progress -> Returning MainActivity.

    My English was wrong, so I got help from a Google translator. I will wait for your answer. I want to say thank you again.

    // Try to create sample files
    if (FileHelper.newSamplesAvailable(this)) {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            Log.d("FileHelper ", "createSamples");
            FileHelper.createSamples(this);
        } else {
            ActivityCompat.requestPermissions(OTA.this, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE);
        }
    }
    
    ...
    
    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 < Build.VERSION_CODES.M)
                            .setPacketsReceiptNotificationsValue(DfuServiceInitiator.DEFAULT_PRN_VALUE)
                            .setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)
                            .setPrepareDataObjectDelay(300L);
    
                    final File root = new File(Environment.getExternalStorageDirectory(), "Nordic");
                    final File file = new File(root, "FILE");
    
                    starter.setZip(file.getPath());
                    final DfuServiceController controller = starter.start(OTA.this, com.example.coolproject.DfuService.class);
                }
            });
    
    ...
    
    private final DfuProgressListener dfuProgressListener = new DfuProgressListenerAdapter() {
            @Override
            public void onDeviceConnecting(final String deviceAddress) {
                otaStateTextView.setText(R.string.dfu_status_connecting);
                Log.d("onDeviceConnecting", deviceAddress);
            }
    
            @Override
            public void onDfuProcessStarting(final String deviceAddress) {
                otaStateTextView.setText(R.string.dfu_status_starting);
                Log.d("onDfuProcessStarting", deviceAddress);
            }
    
            @Override
            public void onEnablingDfuMode(final String deviceAddress) {
                otaStateTextView.setText(R.string.dfu_status_starting);
                Log.d("onEnablingDfuMode ", deviceAddress);
            }
    
            @Override
            public void onDfuCompleted(@NonNull String deviceAddress) {
                super.onDfuCompleted(deviceAddress);
                otaStateTextView.setText(R.string.dfu_status_completed);
                final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.cancel(DfuService.NOTIFICATION_ID);
                Log.d("onDfuCompleted", deviceAddress);
            }
    
            @Override
            public void onError(final String deviceAddress, final int error, final int errorType, final String message) {
                final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.cancel(DfuService.NOTIFICATION_ID);
                Log.d("onError", error + " / " + errorType + " / " + message);
            }
    
            @Override
            public void onDfuAborted(final String deviceAddress) {
                final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.cancel(DfuService.NOTIFICATION_ID);
                Log.d("onDfuAborted", deviceAddress);
            }
        };
        
        ---------
        
        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, OTA.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();
        }
    }

Related