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);
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();