Reputation: 35
I want use Huawei Push Kit in my Appcelerator Titanium app with Hyperloop.
var tokenString = '';
var Activity = require('android.app.Activity');
var ActivityToken = require('com.huawei.hms.aaid.HmsInstanceId');
try{
const activity = new Activity(Ti.Android.currentActivity);
tokenString = ActivityToken.getInstance(activity).getToken(appID, "HCM");
console.log('tokenString', tokenString);
}
catch (e){
console.log(e);
}
But I receive error: "operation in MAIN thread prohibited"
How do I run the code in a separate thread?
Upvotes: 1
Views: 205
Reputation: 2025
Wrap around the code inside background thread, since the error says clearly that this can not be run on main thread. Time consuming calls are usually not allowed in main thread, onCreate etc.
Thread {
…
}.run()
Upvotes: -1
Reputation: 34017
You could try the Automatic Initialization, by calling the setAutoInitEnabled(boolean enable) method in HmsMessaging.
ActivityToken.getInstance(activity).setAutoInitEnabled(true);
The applied token is returned through the onNewToken() method after completing the configuration.
Upvotes: 1