onMessageReceived() never called, although connected to handheld - android

I want to send Messages from a handheld device to a smartwatch (Moto360) only when a message comes up.
I made sure that both modules have the same package name, debug.key and version number.
The listener gets added in onConnected() and the function is always called.
Here is my Handheld gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "de.bachelorthesis.important"
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file("../debug.keystore")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile files('libs/commons-io-2.4.jar')
compile files('libs/mapquest-android-sdk-1.0.5.jar')
compile files('libs/osmdroid-android-4.2.jar')
compile files('libs/slf4j-android-1.7.7.jar')
wearApp project(':wear')
}
In my handheld Activity the message should be sent like this:
private void sendToSmartwatch(msg) {
final String msg_arg = msg;
new Thread(new Runnable() {
public void run() {
mGoogleApiClient = new GoogleApiClient.Builder(getBaseContext())
.addApi(Wearable.API)
.build();
ConnectionResult connectionResult =
mGoogleApiClient.blockingConnect(5, TimeUnit.SECONDS);
NodeApi.GetLocalNodeResult nodes =
Wearable.NodeApi.getLocalNode(mGoogleApiClient).await(3, TimeUnit.SECONDS);
com.google.android.gms.wearable.Node node = nodes.getNode();
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), CONSTANT, msg_arg.getBytes()).await();
Log.d("node:result: ", "" + result.getStatus());
if (result.getStatus().isSuccess()) {
// Log success
}
else {
// Log an error
}
mGoogleApiClient.disconnect();
}
}).start();
}
The Wearable gradle.build file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "de.bachelorthesis.important"
minSdkVersion 20
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file("../debug.keystore")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.support:wearable:1.1.0'
compile 'com.google.android.gms:play-services-wearable:+'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:22.0.0'
}
And eventually, the message should come up here on my watch:
public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
...
onCreate(){
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
mListener = new MessageApi.MessageListener() {
#Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals(CONSTANT)) {
//do stuff with the message
}
}
};
}
#Override
public void onConnected(Bundle bundle) {
Wearable.MessageApi.addListener(mGoogleApiClient, mListener);
}
I have tried several different Listeners like the ListenerService (also with the BIND_LISTENER in the manifest.xml)
Also I have tried the PhoneService Class from this answer.
Any suggestions what I am doing wrong?
EDIT: I forgot to mention that the message gets sent from the handheld successfully, but it is not received.
EDIT 2: Could it be an issue, that my handheld module has the name "app" instead of "mobile"?! Also it is a project that i migrated from eclipse, to add the wearable feature.

So, i figured it out myself:
This project was helping.
I think the Constants made the difference. It was no path, but a randomly set constant by me. Still not sure, tho.

Related

missing binaries for apk to install on device

I have looked at this article
[INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
But i was unable to get any resolution.
right now this is my code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.testapp.testapp"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
splits {
abi {
enable true
reset()
include 'arm64-v8a'
universalApk true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('me.dm7.barcodescanner:zxing:1.9') { exclude module: 'support-v4' }
implementation 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
api 'org.slf4j:slf4j-api:1.7.25'
implementation 'org.slf4j:slf4j-simple:1.7.12'
}
And also my mainactivity
public class MainPage extends AppCompatActivity {
public static NetworkParameters BTCparams = TestNet3Params.get();
public static WalletAppKit BTCkit = new WalletAppKit(BTCparams,new File("."),"BTC-Test");
static String[] account;
static String[] server;
private Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tVBTCPer = (TextView)findViewById(R.id.tVBTCPer);
TextView tVNull = (TextView)findViewById(R.id.tVNull);
tVNull.setText(System.getProperty("os.arch"));
DownloadProgressTracker BTCListener = new DownloadProgressTracker() {
#Override
public void progress(double pct, int blocksSoFar, Date date) {
tVBTCPer.setText((int) pct+"%");
}
#Override
public void doneDownload() {
tVBTCPer.setText("100%");
}
};
BTCkit.setDownloadListener(BTCListener).setBlockingStartup(false).startAsync().awaitRunning();
}
I used this library to make java applications for pc/linux and it works fine. But when im trying to compile this for android to be usable it gets hung up trying to install the apk onto my device.
my os.arch is aarch64. I also have a previous post in stackoverflow to help give it some context.
Bitcoinj library on android hung on installing APK
I am not entirely sure what library i would need to help this apk install onto my device.

Watson Conversation autogenerate Android app - 'Unknown pattern character 'X''

I'm using the auto generated example from IBM Watson Mobile App, but when i tried to run it, it shows an error in the following part of code. I found similar errors around SO, but i think this is another one different.
public ServiceCall<MessageResponse> message(String workspaceId, MessageRequest request) {
Validator.isTrue((workspaceId != null) && !workspaceId.isEmpty(), "'workspaceId' cannot be null or empty");
RequestBuilder builder = RequestBuilder.post(String.format(PATH_MESSAGE, workspaceId));
builder.query(VERSION_PARAM, versionDate);
if (request != null) {
//the error shows here
builder.bodyJson(GsonSingleton.getGson().toJsonTree(request).getAsJsonObject());
} else {
builder.bodyJson(new JsonObject());
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(MessageResponse.class));
}
The following is my build.gradle file:
apply plugin:'base'
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.ibm.watson_conversation"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
manifestPlaceholders = ['appIdRedirectScheme': android.defaultConfig.applicationId]
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
warning 'InvalidPackage'
abortOnError false
}
}
dependencies {
compile ('com.ibm.mobilefirstplatform.clientsdk.android:core:[2.0.0,3.0.0)')
compile 'com.ibm.watson.developer_cloud:conversation:3.8.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
}
The issue was fixed in 3.9.0.
You just need to update the dependency version to be 3.9.1:
compile 'com.ibm.watson.developer_cloud:conversation:3.9.1'

Firebase is firing a database leak

I added firebase inside my app to get some special events like when users open and close their app.
The problem is that every time I launch the app, it crashes right away. It started to happen when I added firebase and when I comment my Firebase code, it's working again, so now I'm pretty sure it's a problem with firebase.
The problem seems to be happening when the onForeground() is called. I tried to put it on a new Thread or call it in a Handler but it keeps crashing...
Here is the stack:
10-28 16:46:26.106 27724-27732/com.package.custom E/System: Uncaught exception thrown by finalizer
10-28 16:46:26.107 27724-27732/com.package.custom E/System: java.lang.IllegalStateException: The database '/data/user/0/com.package.custom/databases/google_app_measurement_local.db' is not open.
at android.database.sqlite.SQLiteDatabase.throwIfNotOpenLocked(SQLiteDatabase.java:2169)
at android.database.sqlite.SQLiteDatabase.createSession(SQLiteDatabase.java:365)
at android.database.sqlite.SQLiteDatabase$1.initialValue(SQLiteDatabase.java:84)
at android.database.sqlite.SQLiteDatabase$1.initialValue(SQLiteDatabase.java:83)
at java.lang.ThreadLocal$Values.getAfterMiss(ThreadLocal.java:430)
at java.lang.ThreadLocal.get(ThreadLocal.java:65)
at android.database.sqlite.SQLiteDatabase.getThreadSession(SQLiteDatabase.java:359)
at android.database.sqlite.SQLiteProgram.getSession(SQLiteProgram.java:101)
at android.database.sqlite.SQLiteQuery.setLastStmt(SQLiteQuery.java:96)
at android.database.sqlite.SQLiteQuery.close(SQLiteQuery.java:111)
at android.database.sqlite.SQLiteCursor.close(SQLiteCursor.java:300)
at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:366)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
at java.lang.Thread.run(Thread.java:818)
Here is a part of my AnalyticsHelper class:
public class AnalyticsHelper
{
//...
/**
* Hook called when the app switch to foreground mode
*/
public static void onForeground()
{
Log.d(TAG, "FOREGROUND");
Bundle bundle = new Bundle();
bundle.putString(KEY_TYPE, AnalyticsCategories.CATEGORY_LIFECYCLE_ACTION_FOREGROUND);
CustomApplication.getAnalytics().logEvent(AnalyticsCategories.CATEGORY_LIFECYCLE, bundle);
}
//...
}
Here is the call of the AnalyticsHelper in the activity:
public class MainActivity extends AppCompatActivity
{
#Override
protected void onResume()
{
super.onResume();
//...
AnalyticsHelper.onForeground();
}
}
And here is the part of the custom Application class:
public class CustomApplication extends Application
{
private static final String TAG = "CustomApplication";
private static CustomApplication sApplication;
public static CustomApplication get()
{
return sApplication;
}
public static FirebaseAnalytics getAnalytics()
{
return get().getFirebaseAnalytics();
}
#Override
public void onCreate()
{
super.onCreate();
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
sApplication = this;
}
/**
* Gets the default {#link Tracker} for this {#link Application}.
*
* #return tracker
*/
public FirebaseAnalytics getFirebaseAnalytics()
{
if (mFirebaseAnalytics == null)
{
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
return mFirebaseAnalytics;
}
}
I searched all the afternoon and nothing came out, please help..
Edit #1 (build.gradle):
apply plugin: 'com.android.application'
android {
signingConfigs {
release {
keyAlias '##########'
keyPassword '##########'
storeFile file('##########')
storePassword '##########'
}
}
compileSdkVersion 25
buildToolsVersion '24.0.2'
defaultConfig {
applicationId "com.custom.app"
minSdkVersion 18
targetSdkVersion 25
android.applicationVariants.all { variant ->
def versionPropsFile = file('src/main/res/raw/version.properties')
if (versionPropsFile.canRead())
{
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['code'].toInteger() + 1
versionProps['code'] = code.toString()
def version = versionProps['version']
versionProps.store(versionPropsFile.newWriter(), null)
versionCode code
versionName version
}
else
{
throw new GradleScriptException('Cant access version.properties');
}
}
signingConfig signingConfigs.release
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "EXPORT_EXTERNAL_STORAGE", "true"
}
debug {
debuggable true
buildConfigField "boolean", "EXPORT_EXTERNAL_STORAGE", "true"
}
}
productFlavors {
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-net-3.3.jar')
//Debug
compile files('libs/commons-lang3-3.5.jar')
compile files('libs/joda-time-2.9.5.jar')
compile project(':android-ble-module')
debugCompile project(path: ':android-log-module', configuration: 'debug')
releaseCompile project(path: ':android-log-module', configuration: 'release')
compile project(':android-location-module')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:preference-v14:25.0.0'
compile 'com.google.android.gms:play-services-gcm:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.google.android.gms:play-services-identity:9.8.0'
compile 'com.google.firebase:firebase-analytics:9.8.0'
}
apply plugin: 'com.google.gms.google-services'
Please move to latest version of firebase SDK. Firebase solved this memory leak issue in their updated sdk. In this case replace this line
compile 'com.google.firebase:firebase-analytics:9.8.0'
with below line.
compile 'com.google.firebase:firebase-analytics:11.0.1'

Issue in Integration GTM (Google Tag Manager ) android

i want to implement Google Tag Manager in android app so i set followwing code
public class MainActivity extends Activity {
private static final String CONTAINER_ID = "GTM-YYYY";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TagManager tagManager = TagManager.getInstance(this);
tagManager.setVerboseLoggingEnabled(true);
PendingResult<ContainerHolder> pending =
tagManager.loadContainerPreferNonDefault(CONTAINER_ID,
R.raw.gtm_default_container);
pending.setResultCallback(new ResultCallback<ContainerHolder>() {
#Override
public void onResult(ContainerHolder containerHolder) {
ContainerHolderSingleton.setContainerHolder(containerHolder);
Container container = containerHolder.getContainer();
if (!containerHolder.getStatus().isSuccess()) {
Log.e("CuteAnimals", "failure loading container");
displayErrorToUser(R.string.load_error);
return;
}
ContainerHolderSingleton.setContainerHolder(containerHolder);
ContainerLoadedCallback.registerCallbacksForContainer(container);
containerHolder.setContainerAvailableListener(new ContainerLoadedCallback());
startMainActivity();
}
}, 2, TimeUnit.SECONDS);
}
}
i also set google play library in my gradle file as below
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "pkg.android.demo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
}
When i put above code ContainerLoadedCallback clas not found as below image
Any idea how can i solve this?
This methods are from example. You have to implement them by yourself if you want.
You can also comment // them and it will work fine. Remove lines with errors.
This classes are shown here to show what can you do with your container.
You can find these classes in the cuteanimal sample. Go to your directory where sdk is located..... /extras/google/google_play_services/tagmanager/cuteanimals

ChannelAPI can not be resolved

I am trying to exchange files between watch and handheld by using the channel API.
But when I tried to open the channel by calling the following code, the ChannelAPI can not be resolved . Its not part of the "wearable" class I am using.
I guess there probably was caused by the wrong Android version. Does anyone know which version should I specify in my config files or how to fix it?
Thanks a lot.
My wear bundle file looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "mywearapp"
minSdkVersion 20
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4096m"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.0'
compile 'com.google.android.gms:play-services-wearable:7.8.0'
compile project(':shared')
}
Wearable.ChannelApi.openChannel(
mGoogleApiClient, node.getId(), "/mypath").setResultCallback(
new ResultCallback<ChannelApi.OpenChannelResult>() {
#Override
public void onResult(ChannelApi.OpenChannelResult openChannelResult) {
if (openChannelResult.getStatus().isSuccess()) {
mChannel = openChannelResult.getChannel();
mChannel.getOutputStream(mGoogleApiClient).setResultCallback(
new ResultCallback<Channel.GetOutputStreamResult>() {
#Override
public void onResult(Channel.GetOutputStreamResult getOutputStreamResult) {
if (getOutputStreamResult.getStatus().isSuccess()) {
mOutputStream = getOutputStreamResult.getOutputStream();
} else {
// handle failure, and close channel
}
}
});
}
}
});

Categories

Resources