Android. JNI. how to get username !?
-
Good day. tell me please. How do I know login or e-mail user Android device?
I tried to write on Java(JNI). but the code is not running.
package org.qtproject.example.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;import android.accounts.AccountManager;
import android.accounts.Account;
import java.util.List;
import java.util.LinkedList;public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
{
static NotificationManager m_notificationManager;
static Notification.Builder m_builder;
static NotificationClient m_instance;static AccountManager manager; static Account[] accounts; static List<String> possibleEmails; public NotificationClient() { m_instance = this; } public static void notify(String s) { if (m_notificationManager == null) { m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE); m_builder = new Notification.Builder(m_instance); m_builder.setSmallIcon(R.drawable.icon); m_builder.setContentTitle( getUsername() ); } m_builder.setContentText(s); m_notificationManager.notify(1, m_builder.build()); } public static String getUsername() { manager = AccountManager.get(this); accounts = manager.getAccountsByType("com.google"); possibleEmails = new LinkedList<String>(); for (Account account : accounts) { possibleEmails.add(account.name); } if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) { String email = possibleEmails.get(0); String[] parts = email.split("@"); if (parts.length > 1) return parts[0]; } return "null"; }
}
-
i try this too.
but i have: JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception 'java.lang.IllegalArgumentException' thrown in unknown throw locationpackage org.qtproject.example;
import android.accounts.AccountManager;
import android.accounts.Account;public class Android_info extends org.qtproject.qt5.android.bindings.QtActivity{
static Android_info m_instance; public Android_info(){ m_instance = this; } public static String return_mail(){ AccountManager am = AccountManager.get(m_instance); Account[] accounts = am.getAccountsByType("com.google"); return accounts[0].name; }
}
-
This post is deleted! -
this code workink fine on java android. but JNI+Qt its not working.
package org.qtproject.example;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;import android.accounts.AccountManager;
import android.accounts.Account;public class Android_info extends org.qtproject.qt5.android.bindings.QtActivity{
static Android_info m_instance; public Android_info(){ m_instance = this; } public static String return_mail(){ AccountManager am = AccountManager.get(m_instance); Account[] accounts = am.getAccountsByType("com.google"); return accounts[0].name; }
}
-
intellij idea output:
java.lang.IllegalStateException: System services not available to Activities before onCreate():(