How to save a phone number in an incoming call in Flutter - flutter

I want to get the incoming caller's phone number in my flutter app.
I'm trying the solution in this answer, but it doesn't work.
I have no knowledge about it at all and have not been able to find a resource with all the stages. What am I doing wrong?
The full code: https://github.com/gulsenkeskin/phone_call_demo

I solved the problem. If anyone needs it, he can look at this link

You can't do this in Flutter. To receive incoming call you should go for native, in the number String you will receive the incoming caller's number.
package com.anand.example;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public class CallReceiver extends BroadcastReceiver {
String number = "";
#Override
public void onReceive(Context context, Intent intent) {
number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (number != null) {
if (number != null) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
System.out.println(number);
// call attended
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// call ended
System.out.println(number);
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
System.out.println(number);
// incoming call
}
}
}
}
}

Related

How to connect a Phantom wallet to my Flutter web app?

I've been trying unsuccesfully to connect a Flutter web app to a Phantom wallet. No pub.dev packages have been released in order to accomplish this and can't figure out how to do it with dart-js interop.
Wondering if someone already figured it out?
I have a (crude) working piece of code that could be useful for somebody trying to accomplish the same:
// web/index.html
<script src="../lib/wallet.js" />
// wallet.js
class ClientWallet {
constructor() {
this.pubKey = '';
}
async connect() {
const resp = await window.solana.connect();
this.pubKey = resp.publicKey.toString();
}
address() {
return this.pubKey;
}
disconnect() {
window.solana.disconnect();
}
}
var walletModule = { ClientWallet: ClientWallet };
// main.dart
import 'package:js/js.dart';
import 'package:js/js_util.dart';
#JS('walletModule.ClientWallet')
class ClientWallet {
external Future<void> connect();
external void disconnect();
external String get pubKey;
}
Future<void> connectWallet() async {
ClientWallet wallet = ClientWallet();
await promiseToFuture(wallet.connect());
}
And then for connecting simply call connectWallet(). This works for me for the Phantom wallet, now I'm trying to integrate the Solana Dart package for signing a transaction.

why flutter static final variable changed

I am define a static final variable in flutter using configuration package like this:
class GlobalConfig {
static final GlobalConfiguration config = GlobalConfiguration();
}
to my understand, the config should initial once when load the class, then keep the same all the time until close the app. But now the config has different value in app running. It make me sometimes read config success, sometimes failed. This is my full code of GlobalConfig class:
import 'package:global_configuration/global_configuration.dart';
enum ConfigType { DEV, PRO }
class GlobalConfig {
GlobalConfig(this.baseUrl, this.shareUrl, this.staticResourceUrl);
static final GlobalConfiguration config = GlobalConfiguration();
String baseUrl = config.get("baseUrl");
String shareUrl = config.get("shareUrl");
String staticResourceUrl = config.get("staticUrl");
static getBaseUrl() {
String configBaseUrl = config.get("baseUrl");
return configBaseUrl;
}
static getShareUrl() {
return config.get("shareUrl");
}
static getStaticResourceUrl() {
return config.get("staticUrl");
}
static getConfig(String key) {
return config.get(key);
}
static init(ConfigType configType) {
switch (configType) {
case ConfigType.DEV:
break;
case ConfigType.PRO:
break;
}
}
}
is there any way to make the config keep the same and do not change? or what should I do to make read the config keep stable? I want the config read all success or all failed. this is the success reading when debbuging:
this is the read faild debbuing:
the breakpoint was entered after the app configuration loaded complete. BTW, my project is open source, all the source code from here. The basic logic is when playing music, I send a http request to save the songs info to my own server. the function is: ReddwarfMusic.savePlayingMusic, this function read a global config of my own server url. The RM radio page add favirate save reading config success, but auto save from FM radio read config failed. I tried to make the config final static but not fixed it. So I thinking for days and do not know how to make it work.
TRIED:
now I tweak the code like this:
import 'package:global_configuration/global_configuration.dart';
enum ConfigType { DEV, PRO }
class GlobalConfig {
static Map config = Map<String, String>();
GlobalConfig() {
}
static getBaseUrl() {
String configBaseUrl = config["baseUrl"];
return configBaseUrl;
}
static getShareUrl() {
return config["shareUrl"];
}
static getStaticResourceUrl() {
return config["staticUrl"];
}
static getConfig(String key) {
return config[key];
}
static init(ConfigType configType) {
var globalConfig = GlobalConfiguration();
if (globalConfig.appConfig.isNotEmpty) {
config = Map.unmodifiable(globalConfig.appConfig);
}
switch (configType) {
case ConfigType.DEV:
break;
case ConfigType.PRO:
break;
}
}
}
but the config seems initial every time. First I set the config success, but when I use, the config changed to null.
this is the initial code:
var globalConfig = GlobalConfiguration();
if (globalConfig.appConfig.isNotEmpty) {
config = Map.unmodifiable(globalConfig.appConfig);
}
I am sure the initial config success.
I finnaly find one type of invoke was send from background service pragma entry point, so the configuration should initial in background service too. This is the entry look like:
import 'package:flutter/material.dart';
import 'package:music_player/music_player.dart';
import 'package:quiet/app.dart';
import 'package:quiet/component.dart';
import 'package:quiet/repository/netease.dart';
import 'package:wheel/wheel.dart';
void main() {
CommonUtils.initialApp(ConfigType.PRO).whenComplete(() => {loadApp(ConfigType.PRO)});
}
/// The entry of dart background service
/// NOTE: this method will be invoked by native (Android/iOS)
#pragma('vm:entry-point') // avoid Tree Shaking
void playerBackgroundService() {
CommonUtils.initialApp(ConfigType.PRO).whenComplete(() => {
loadRepository()
});
}
void loadRepository() {
WidgetsFlutterBinding.ensureInitialized();
GlobalConfig.init(ConfigType.PRO);
neteaseRepository = NeteaseRepository();
runBackgroundService(
imageLoadInterceptor: BackgroundInterceptors.loadImageInterceptor,
playUriInterceptor: BackgroundInterceptors.playUriInterceptor,
playQueueInterceptor: QuietPlayQueueInterceptor(),
);
}
I don't know why the background service could not read the configuration.

How to download and install NFC sample applet on Fudan FM1280 dual interface card?

I have a dual interface Fudan FM1280 which supports both contact (ISO7816) and contactless (ISO14443) interfaces connected to the same chip card. All I want to do is to install an HCI applet on this card.
To do so, I have used the example code from Simalliance (Mobile Near Field Communication (Mobile NFC) Stepping Stones) named "a Reader Mode Applet based on ToolKit interaction". The source code for that example is as below:
package pkgReaderModeApplet;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.MultiSelectable;
import uicc.toolkit.ToolkitConstants;
import uicc.toolkit.ToolkitException;
import uicc.toolkit.ToolkitInterface;
import uicc.toolkit.ToolkitRegistry;
import uicc.hci.framework.HCIDevice;
import uicc.hci.framework.HCIMessage;
import uicc.hci.framework.HCIService;
import uicc.hci.services.connectivity.ConnectivityService;
import uicc.hci.services.readermode.ReaderListener;
import uicc.hci.services.readermode.ReaderMessage;
import uicc.hci.services.readermode.ReaderService;
public class ReaderModeApplet extends Applet implements ReaderListener, MultiSelectable, ToolkitConstants, ToolkitInterface {
private ToolkitRegistry myToolKitReg;
private HCIService myReaderService;
private ConnectivityService myConnectivityService;
private ReaderModeApplet() {
myReaderService = (ReaderService) HCIDevice.getHCIService(HCIDevice.READER_SERVICE_ID);
myReaderService.register(this);
}
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new ReaderModeApplet().register();
}
public void processToolkit(short event) throws ToolkitException {
switch(event) {
case EVENT_MENU_SELECTION:
myReaderService.activateEvent(ReaderListener.EVENT_TARGET_DISCOVERED);
break;
case EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY:
myToolKitReg.clearEvent(EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY);
break;
}
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
public void onCallback(byte event, HCIMessage myHCIMessage) {
// First: Reception of Datas
short offset = myHCIMessage.getReceiveOffset();
short length = myHCIMessage.getReceiveLength();
byte[] IncomingBuffer = myHCIMessage.getReceiveBuffer();
switch(event){
//Target Discovered !!!
case ReaderListener.EVENT_TARGET_DISCOVERED:
//Activation of relevant events
myReaderService.activateEvent(ReaderListener.EVENT_WRITE_EXCHANGE_DATA_RESPONSE);
myReaderService.activateEvent(ReaderListener.EVENT_GET_PARAMETER_RESPONSE);
// Check if status is OK
if (IncomingBuffer[(short)(offset) ] == ReaderMessage.SINGLE_TARGET_STATUS) {
// Copy your Datas into IncomingBuffer
// and send the first message
// prepareAndSendWriteXchgDataCommand(byte timeout, byte[] data, short offset, short len)
((ReaderMessage)myHCIMessage).prepareAndSendWriteXchgDataCommand((byte) -1, IncomingBuffer, (short)offset, (short)length);
// Or retrieves informations on the Target discovered
((ReaderService)myReaderService).getReaderRFType();
((ReaderMessage)myHCIMessage).prepareAndSendGetParameterCommand(ReaderMessage.
PARAM_ID_TYPE_B_READER_AFI);
} else {
// If status is equal to MULTIPLE_TARGET_STATUS
((ReaderMessage)myHCIMessage).restartReaderModeProcedure();
// Warn the user
}
break;
//Response received !!
case ReaderListener.EVENT_WRITE_EXCHANGE_DATA_RESPONSE:
//First check if response is a Success
if(myHCIMessage.getInstruction() == (byte)(HCIMessage.RESP_ANY_OK)) {
//Copy your Datas into IncomingBuffer
// and send your next message
((ReaderMessage)myHCIMessage).prepareAndSendWriteXchgDataCommand((byte) -1, IncomingBuffer, (short)offset, (short)length);
// Or you have all the datas and you want to process them
myToolKitReg.setEvent(ToolkitConstants.EVENT_EVENT_DOWNLOAD_HCI_CONNECTIVITY);
myConnectivityService = (ConnectivityService)HCIDevice.getHCIService(HCIDevice.CONNECTIVITY_SERVICE_ID);
myConnectivityService.prepareAndSendConnectivityEvent();
myReaderService.deactivateEvent(ReaderListener.EVENT_TARGET_DISCOVERED);
} else {
//Or restart the procedure
((ReaderMessage)myHCIMessage).restartReaderModeProcedure();
}
break;
case ReaderListener.EVENT_GET_PARAMETER_RESPONSE:
default:
break;
}
}
public void deselect(boolean arg0) {
// TODO Auto-generated method stub
}
public boolean select(boolean arg0) {
// TODO Auto-generated method stub
return true;
}
}
I am using Java card 2.2.2, hci-api-for-java-card-REL-920 and uicc-api-for-java-card-REL-13_0 to compile this code (using Eclipse) and it results in the cap file needed to be downloaded on card.
I am using pyApduTool to interface card. As I connect to card and try to download this applet on my card, I get an error as below and never get to installing step for the downloaded file.
This card originally contains few packages as:
And no applet installed. Now, what is the problem with applet downloading on card?

Costum Event Handling

I issue I am trying to get rid off is the following:
I intend to setup a costum event handling chain as a workaround for JavaFX's lack of actioncommands.
The issue in particular is, that a menuitem upon clicking it, still fires an ActionEvent instead of the self-written MilvaLabActionEvent.
The code:
Event class
package jpt.gui.items;
import javafx.event.ActionEvent;
public class MilvaLabActionEvent extends ActionEvent {
private static final long serialVersionUID = 6757067652205246280L;
private String actionCommand ="";
public MilvaLabActionEvent(String actionCommand2) {
setActionCommand(actionCommand2);
}
public MilvaLabActionEvent() {}
public String getActionCommand() {
return actionCommand;
}
public void setActionCommand(String actioncommand) {
this.actionCommand = actioncommand;
}
}
My EventHandler:
package jpt.gui.items;
import javafx.event.EventHandler;
import jpt.MilvaLabGlobal;
import jpt.MilvaLabKonst;
import jpt.handle.MilvaLabDateiHandle;
import jpt.handle.MilvaLabEinHandle;
import jpt.handle.MilvaLabHilfeHandle;
import jpt.handle.MilvaLabMilvaHandle;
import jpt.handle.MilvaLabRvAnwendungHandle;
import jpt.handle.MilvaLabrvTextHandle;
import jpt.log4j.MilvaLabLogger;
public class MilvaLabEventHandler implements EventHandler<MilvaLabActionEvent>{
#Override
public void handle(MilvaLabActionEvent event) {
// the command string of the menu item
final String sCmd = event.getActionCommand();
if (sCmd.charAt(0) == 'M')
{//doing something here
}
}
The costum MenuItem-Class I figured out I gotta write.
package jpt.gui.items;
import javafx.event.Event;
import javafx.scene.control.MenuItem;
public class MilvaLabMenuItem extends MenuItem {
private String actionCommand;
public MilvaLabMenuItem(String sText) {
this.setText(sText);
}
#Override
public void fire() {
Event.fireEvent(this, new MilvaLabActionEvent(getActionCommand()));
}
public String getActionCommand() {
return actionCommand;
}
public void setActionCommand(String actionCommand) {
this.actionCommand = actionCommand;
}
}
And the initialization of the costum MenuItem:
final MilvaLabMenuItem jmi = new MilvaLabMenuItem("I am a menuItem");
jmi.addEventHandler(evtype, new MilvaLabEventHandler());
jmi.setOnAction((event) -> {
System.out.print("I have fired an ActionEvent!");
});
Well, as of now, I got "I have fired an ActionEvent" when I click on the MilvaLabMenuItem, nothing else happens. (Looked into that thing already using the debugger).
What I want to happen is that, obviously, the MilvaLabEventHandler is called.
I figured it out again.
I declared two EventTypes, though, only one was necessary.
This helped me finding the solution, though, they use Nodes instead of MenuItems.
How to emit and handle custom events?

Display error messages directly in Vaadin 7

I'm developing a web app in Vaadin, which involves a large number of forms. Currently, all the screens have been created, and I ran them past a couple of test users (4) to checkout their usability. All of them had one and the same comment; when a validation error occurred, it was not clear what the problem was. None of them thought about hovering their mouse over the error indicator (if they even noticed the indicator) to get the precise error message.
I read in the Book of Vaadin that the placement of the error indicator is managed by the layout in which the component is contained. However, it doesn't seem to say anything about directly showing the error message. Is it possible to do this (preferrably, without having to implement a custom widget set)?
Thanks,
​William
I don't think what you have in mind is implemented with vaadin's basic components.
I suggest the following approach: create a dedicated label above the form's input components that is invisible by default. After validation, if there are errors, add them all to the label's text and make it visible. Displaying the errors right next to the component that caused the validation error would likely mess up your layout too much anyway.
I write a utility class to do this:
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Page;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
public class ErrorUtils {
public static List<String> getComponentError(
final AbstractComponent[] componentArray) {
List<String> errorList = new ArrayList<String>();
for (AbstractComponent component : componentArray) {
ErrorMessage errorMessage = component.getErrorMessage();
if (errorMessage != null) {
errorList.add(errorMessage.getFormattedHtmlMessage());
}
}
return errorList;
}
public static List<String> getComponentError(
final Collection<?> componentCollection) {
AbstractComponent[] componentArray = componentCollection
.toArray(new AbstractComponent[] {});
return ErrorUtils.getComponentError(componentArray);
}
public static void showComponentErrors(
final AbstractComponent[] componentArray) {
List<String> errorList = ErrorUtils.getComponentError(componentArray);
String error = StringUtils.join(errorList, "\n");
Notification notification = new Notification("Error", error,
Type.ERROR_MESSAGE, true);
notification.show(Page.getCurrent());
}
public static void showComponentErrors(
final Collection<?> componentCollection) {
AbstractComponent[] componentArray = componentCollection
.toArray(new AbstractComponent[] {});
ErrorUtils.showComponentErrors(componentArray);
}
}
The the following code is a simple sample showing how to use it:
private void saveButtonClicked() {
// this method is the handler of the click event of the [save] button
try {
this.fieldGroup.commit();
} catch (CommitException e) {
// Show all the validate errors:
ErrorUtils.showComponentErrors(this.fieldGroup.getFields());
return;
}
// save data, if there is no validate error
}
I created a Vaadin Add-on that will display validation/conversion error messages directly on the UI rather than in a tooltip.
Check it out here:
https://vaadin.com/directory#!addon/validation-error-display