System UI crashes while requesting USB access permission using USB host api

I was trying to access a usb device attached to an android M mobile using USB host api , the code looks like below :-

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";


private TextView tvPath;

private boolean permissionGranted=false;


private static final String ACTION_USB_PERMISSION =
        "com.android.example.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ACTION_USB_PERMISSION.equals(action)) {
            synchronized (this) {
                    UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                        if (device != null) {
                        }
                        permissionGranted=true;
                    } else {
                        Log.d(TAG, "permission denied for device " + device);
                    }
                }
            }
        }

};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tvPath=findViewById(R.id.path);


    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

    PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    registerReceiver(mUsbReceiver, filter);

    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        tvPath.setText(device.getDeviceName());

        manager.requestPermission(device, permissionIntent); // system ui crashes here


    }
}

}

It detects the usb device , but on requesting permission to access the device it crashes the system UI with the following exception :-

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.systemui/com.android.systemui.usb.UsbPermissionActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5769)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
    at com.android.systemui.usb.UsbPermissionActivity.onCreate(UsbPermissionActivity.java:120)
    at android.app.Activity.performCreate(Activity.java:6583)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2531)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493) 
    at android.os.Handler.dispatchMessage(Handler.java:111) 
    at android.os.Looper.loop(Looper.java:207) 
    at android.app.ActivityThread.main(ActivityThread.java:5769) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 

The manifest file looks like below:-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.filedemo">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"> 
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-feature android:name="android.hardware.usb.host"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest> 

According to documentation

If you want your application to be notified of an attached USB device, specify an and element pair for the android.hardware.usb.action.USB_DEVICE_ATTACHED intent in your main activity.

So I have not added any this intent filter as I am enumerating USB devices . I am unable find if I have done anything wrong ! Any help will be appreciated .

Is using USB host api the best way to access USB devices on android ?