Checking wether a value exists or not in Firebase - android

I have one small code i don't know how to do it.
I have Realtime database in firebase,
and i want check if child name is exist or not.
example:
Realtime database:
i tried before this code and the compiler is pass from this code and not execute it or going to check.
mDatabase.child ( "Voted" ).child ( DataTeamVote.name.get ( position ) ).addListenerForSingleValueEvent ( new ValueEventListener ( )
{
#Override
public void onDataChange ( DataSnapshot snapshot )
{
if ( snapshot.hasChild ( mAuth.getCurrentUser ( ).getUid ( ) ) )
{
check = false;
Toast.makeText ( VoteAction.this , "You are already voted for this team" , Toast.LENGTH_SHORT ).show ( );
}
else
{
check = true;
Toast.makeText ( VoteAction.this , "Open Vote" , Toast.LENGTH_SHORT ).show ( );
}
}
#Override
public void onCancelled ( #NonNull DatabaseError databaseError )
{
}
} );

Related

BillingClient isFeatureSupported returns SERVICE_DISCONNECTED

I'm working with the Google Billing Library Version 5. I've pretty
much gotten my code to do the right thing. I tested it on hardware
devices running API levels 16, 23, 28, and 32.
Then I did a factory reset on the device running API level 23. I
wanted to establish a brand new Google ID to test the billing library.
It's a Samsung Galaxy S5 running Android M. Purchasing no longer
works. billingClient.isReady returns false, and
billingClient.isFeatureSupported returns SERVICE_DISCONNECTED.
onBillingServiceDisconnected is not being called.
billingClient.queryPurchasesAsync() does work. It returns an OK response
code and reports zero purchases.
My code runs fine on my other devices, and it used to run fine on the
Galaxy S5 until I reset it and gave it a new user ID.
https://developer.android.com/google/play/licensing/setting-up says I
should be running on a device that has the Google Play client
pre-installed. The Applications Manager shows a Google Play Store app
with the same version number as my other devices. Ditto for Google
Play Services. The Play Store app tells me it is up to date.
What am I missing?
public void doPurchase( Activity activity )
{
billingClient = BillingClient.newBuilder(activity).enablePendingPurchases()
.setListener(this).build();
if ( ! billingClient.isReady() )
Log.i( appName, "Billing client is not ready" );
BillingResult billingResult = billingClient.isFeatureSupported( BillingClient.FeatureType.PRODUCT_DETAILS );
if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
{
Log.i( appName, String.format( "feature not supported %s", billingResult.toString() ) );
return;
}
billingClient.startConnection(new BillingClientStateListener()
{
public void onBillingSetupFinished( #NonNull BillingResult billingResult )
{
if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
{
Log.i( appName, String.format( "billing setup response code %s", billingResult.toString() ) );
return;
}
launchPurchase( activity );
}
public void onBillingServiceDisconnected()
{
Log.i( appName, "Disconnected" );
}
});
}
private void launchPurchase( final Activity activity )
{
ImmutableList<QueryProductDetailsParams.Product> productList
= ImmutableList.of( QueryProductDetailsParams.Product.newBuilder()
.setProductId( SKU_BUY )
.setProductType( BillingClient.ProductType.INAPP)
.build());
QueryProductDetailsParams.Builder builder = QueryProductDetailsParams.newBuilder();
builder.setProductList( productList );
billingClient.queryProductDetailsAsync( builder.build(),
new ProductDetailsResponseListener() {
#Override
public void onProductDetailsResponse( #NonNull BillingResult billingResult,
#Nullable List<ProductDetails> list ) {
if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
{
Log.i( appName, String.format( "product details response code %s", billingResult.toString() ) );
return;
}
if ( list == null || list.size() <= 0 )
{
Log.i( appName, "no products found" );
return;
}
ImmutableList<BillingFlowParams.ProductDetailsParams> deetsParams = ImmutableList.of(
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails( list.get( 0 ) )
.build() );
BillingFlowParams purchaseParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList( deetsParams )
.build();
billingClient.launchBillingFlow( activity, purchaseParams );
}
} );
}

react-native RECEIVE_SMS android permission always results 'never_ask_again'

I am requesting multiple permissions. All are working fine except receive sms where the result is always 'never_ask_again'.
The following is the code I am trying:
_getPermissions = async () => {
try {
const resuts = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE
]);
if (
resuts[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] !==
PermissionsAndroid.RESULTS.GRANTED
) {
alert("Permission not granted. The application may not work properly");
}
if (
resuts[PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE] !==
PermissionsAndroid.RESULTS.GRANTED
) {
alert("Permission not granted. The application may not work properly");
}
if (
resuts[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] !==
PermissionsAndroid.RESULTS.GRANTED
) {
alert("Permission not granted. The application may not work properly");
}
} catch (err) {
console.warn(err);
}
};
Fix this line as opposite condition:
if (
resuts[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] ===
PermissionsAndroid.RESULTS.DENIED
) {
Alert.alert("Permission not granted. The application may not work properly");
}

Android Permissions dialog box not coming

I have a phone number activity as well as phone number controller class
I have defined my checkpermission and requestpermission in my standard methods and calling them from controller class as shown below:
public static boolean checkPermission ( Context context ) {
Log.e ( "checkPermission: " + context.getClass ( ) );
if (ContextCompat.checkSelfPermission (context,
Manifest.permission.READ_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED)
return true;
return false;
public static void requestPermission ( Activity activity ) {
Log.e ( "AA---->>>", "requestPermission: " + activity.getClass ( ) );
ActivityCompat.requestPermissions ( activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);
}
calling from controller:
boolean isPermissionGiven = StandardMethods.checkPermission ( phoneActivity );
if ( !isPermissionGiven ) {
StandardMethods.requestPermission ( phoneActivity );
}
gives this Error :
E/Utkarsh---: checkPermission: class .PhoneNumberActivity
E/Utkarsh---->>>: requestPermission: class.PhoneNumberActivity
V/FA: Activity resumed, time: 80577484
V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 19
V/FA: Activity paused, time: 80577499
E/Utkarsh---: checkPermission: class.PhoneNumberActivity
V/FA: Activity resumed, time: 80577732
As per logs checkpermission and requestpermission is called
The permission i requested were:
public static boolean checkPermission ( Context context ) {
if ( hasPermission ( context, Manifest.permission.READ_EXTERNAL_STORAGE ) )
return true;
else if ( hasPermission ( context, Manifest.permission.WRITE_EXTERNAL_STORAGE ) )
return true;
else if ( hasPermission ( context, Manifest.permission.READ_SMS ) )
return true;
else if ( hasPermission ( context, Manifest.permission.SEND_SMS ) )
return true;
else if ( hasPermission ( context, Manifest.permission.RECEIVE_SMS ) )
return true;
return false;
}
private static boolean hasPermission ( Context context, String flag ) {
return ContextCompat.checkSelfPermission ( context, flag ) != PackageManager.PERMISSION_GRANTED;
}
There was some problem with "SEND SMS" Permission , it always sends permission not granted i dont know why , though i am not sending sms in my app so i removed it . Removing this made my error gone . Before that the error keeps coming infinitely , I dont know why it helped . Though the same permissions works great if written inside activity . Now they are are in non activity class (Standard Methods).
Please can some one provide the reason

Delay access to property in ionic 2 class

I have a non static traduction file that I periodically get from a server. I cannont change the format of the file.
When I a new page is instanciate in my Ionic App I set this.traductions from a value in storage. See constructor below :
constructor(storage: Storage, public navCtrl: NavController, public navParams: NavParams, public commandeService: CommandeService, public alertCtrl: AlertController, public translate: TranslateService) {
this.categorie = this.navParams.get('categorie');
storage.get('boissons').then((StringBoissons) => {
var boissons: Array<any> = JSON.parse(StringBoissons);
this.boissons = boissons.filter(
(value) => {
return value.tboi_id == this.categorie.tboi_id;
});
}
);
storage.get('traductions').then((val) => {
this.traductions = JSON.parse(val);
});
this.commande = commandeService.getCommande();
this.translate = translate;
}
Then my View call getTraduction(...)
getTraduction(table, champ, id, objet) {
var traduction = this.traductions.find( (value) => {
return value.trad_table == table && value.trad_champ == champ && value.trad_code_langue == this.translate.currentLang && value.trad_id_item == objet[id];
});
if ( traduction && traduction.trad_texte )
return traduction.trad_texte;
else
return objet[champ];
}
Everything works fine in browser preview but on device I get a
Cannot call method 'find' of null
at t.getTraduction
I think it is due to asynchronous results but I can't quite get my head around it and figure how to solve this.
Thanks in advance for any insight
OK quite dumb question actually Sylvain :
You should have put your getTraduction function in a provider.
#Injectable()
export class TraductionDynaService {
traductions;
constructor(
public storage: Storage,
public http: Http,
public translate: TranslateService,
) {
storage.get('traductions').then((val) => {
this.traductions = JSON.parse(val);
});
}
getTraduction(table, champ, id, objet) {
var traduction = this.traductions.find( (value) => {
return value.trad_table == table && value.trad_champ == champ && value.trad_code_langue == this.translate.currentLang && value.trad_id_item == objet[id];
});
if ( traduction && traduction.trad_texte )
return traduction.trad_texte;
else
return objet[champ];
}
}
And it worked like a charm. getTraduction(...) could even return a promise to handle when traduction is null or undefined...

Android StrikeThrough span not working on spaces

Better I put my question as an example
I have the word FREE in a textview
I apply a strikethrough(EXC, EXC) span to the word FREE so I get FREE
Then I insert spaces between the letters and here comes the problem, because I get
F R E E but I want F R E E
It seems it only happens with spaces(I also tried "\u00a0"), because I also tried to insert a normal character (L) and there was no problem, the result was FLRLELE and not FLRLELE.
Any help is appreciated.
Thanks
Are you applying the span character by character, or to the entire substring?
I was having the same problem when I tried the former approach; but when I changed to the latter, it worked perfectly.
Here is an excerpt of the code I used.
The if conditions add a padding of strikethrough around the substrings.
// ↑↑↑ Several layers of loops... :-X
mySubString = textview_Text.substring ( indexStart, indexEnd );
for ( Integer charIndex = 0 ; charIndex < mySubString.length() ; charIndex++ )
{
charOfIndex = String.valueOf ( mySubString.charAt ( charIndex ) );
if ( charIndex > 0 )
{ charOfIndex_Previous = String.valueOf ( mySubString.charAt ( charIndex - 1 ) ); }
else
{ charOfIndex_Previous = charOfIndex; }
if ( charIndex < mySubString.length() - 1 )
{ charOfIndex_Next = String.valueOf ( mySubString.charAt ( charIndex + 1 ) ); }
else
{ charOfIndex_Next = charOfIndex; }
if ( ( charOfIndex.equals ( charSpace ) )
&& ( ! charOfIndex_Next.equals ( charSpace ) ) )
{ spanStart = indexFromPreviousLoop + charIndex; }
if ( ( ! charOfIndex_Previous.equals ( charSpace ) )
&& ( charOfIndex.equals ( charSpace ) ) )
{ spanEnd = indexFromPreviousLoop + charIndex + 1; }
}
mySpannable.setSpan ( new StrikethroughSpan (), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE );

Categories

Resources