0

In te below code I am trying to create a folder for persisted data. As you see I created private final String folder = "//temp"; and the object persistence. But the problem is when i run the App, i says Connection Failed, this message comes out from the client connection synchronous listener, and when I connect without the object persistence, every thing works fine.

Am i wrongly initializing the folder variable or using MqttClientPersistence persistence incorrectly?

code:

private final String folder = "//temp";
private final int keepAliveInterval = 30;
private final String TAG = this.getClass().getSimpleName();

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

        final MqttClientPersistence persistence = new MqttDefaultFilePersistence(folder);  
        final MqttAndroidClient client2 = new MqttAndroidClient(getApplicationContext(), serverURI, clientID,persistence);
Amrmsmb
  • 1
  • 27
  • 104
  • 226

1 Answers1

0

Do you have filesystem read/write permissions enabled for your android application?

Also the path probably wants to be application specific directory. You can get the application specific directory using something like this:

File outputDir = context.getCacheDir();

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • isnt it this permission: ? – Amrmsmb Nov 14 '14 at 14:56
  • yes, you need that, but you can still only write to specific areas of the storage related to your application. The line of code will give you a File object that points to a writable directory – hardillb Nov 14 '14 at 15:01
  • I declared this "private final File outPutDirctory = this.getCacheDir();" and should i use "outPutDirectory.createTempFile" please let me know – Amrmsmb Nov 14 '14 at 15:10