Opening Firebase Dynamic Link with android app without FirebaseDynamicLinks - java

I have an application at the Google Play and there are already a few hundred of users.
Now, I'm working on an update that will allow users to share user-to-user content via Firebase Dynamic Links.
In order to do so, I created a subdomain and all the required things and I added this code:
FirebaseDynamicLinks.getInstance()
.getDynamicLink( getIntent() )
.addOnSuccessListener( this, pendingDynamicLinkData -> {
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String bookID = deepLink.getQueryParameter( "id" );
if (bookID != null) {
startBookDetailActivity( bookID );
}
}
} )
.addOnFailureListener( this, e -> {
}
);
However, the users who already have the app installed on their phone don't have this piece of code in their application which means that if they click on the dynamic link it won't do the job.
Is there any other way I can handle the dynamic link for the period until all users get the latest version?
Thank you

You could have the user copy and past the code into the app but ultimately, this also requires that the app is updated to do so.
Perhaps you could use a cloud function that would return the data in the browser rather than the app, you could do this with a button that appears after a second and manually invoke the call.
But it might just be easier to encourage users to update and implement a callback system using real-time or firestore as a user inbox system for this kind of edge case.

Related

How can I share a db file between 2 applications

since Enviroment.getExternalStorageDirectory() is deprecated I have a little Problem. I have 2 applications (a lite and a pro version of an app). These apps have a database which I could export and import. When switching from lite to pro app, the user could import the "old" database into the new app. The database was stored under a folder inside his "sdcard". But now on Android 12 devices we no longer have access to that External Storage.
So how could I solve the problem?
Cause I think, context.getExternalFilesDir((Environment.DIRECTORY_DOCUMENTS)
doesn't work cause the namespace of both apps are different. And I guess it will not work to open a file which is not located under the namespace of the app the file is requested.
Yes, sharing the app's shared memory with another one is not possible.
Other options are using a external server / Firbase to create profile for users and store there data in it.
The easiest way is not to have two apps. Make the single app work for both modes, and gate features at runtime based on the type of license. You can even make the upgrade an in app purchase.
I found a solution by myself, but if someone else is looking for a solution it might be helpful.
I ask the user to specify a file location via
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/db");
intent.putExtra(Intent.EXTRA_TITLE, "xyz.db");
mCreateNewDatabaseFile.launch(intent);
then in the mCreateNewDatabaseFile
private final ActivityResultLauncher<Intent> mCreateNewDatabaseFile = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == RESULT_OK) {
if (result.getData() != null && result.getData().getData() != null) {
Uri path = result.getData().getData();
getContentResolver().takePersistableUriPermission(path, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(path, Intent.FLAG_GRANT_READ_URI_PERMISSION);
mPreferences.edit().putString(PREF_KEY_DATABASE_EXPORT_PATH, path.toString()).apply();
}
}
});
So even with another process I can read and write the file.
So in the lite Version I can create the db file and in the pro version I can let the user choose this file for import.
I hope it will help others with similar questions.
You can (should) use a ContentProvider to have other apps query your database using accessible methods of your ContentProvider :
you can configure a content provider to allow other applications to
securely access and modify your app data
(this will enforce Single-responsibility principle)

Handling a deep link from the google assistant in Java

Looking to handle a deep link from the Google Assistant. As I only have an emulator at the moment I am having trouble testing it (from what I have read it requires a real device). That said, I was wondering if I am handling it the correct way. I am unfamiliar with Kotlin and my code was turning into Spaghetti trying to integrate, so I put this together in my existing launcher activity just to try and get it bootstrapped for now. The manifest and actions.xml were set up like the fitness app tutorial.
Am I doing this correctly?
if (mAuth.getCurrentUser() != null) {
data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
uriData = data.toString();
containsStart = containsIgnoreCase(uriData,"start");
containsRun = containsIgnoreCase(uriData,"run");
if(containsStart && containsRun) {
Intent intent = new Intent(getApplication(), RunActivity.class);
intent.putExtra("runStart", true);
startActivity(intent);
}
}
else {
checkUserAccType();
}
//Else, if there is no current user, start the Authentication activity
}
A few observations and recommendation about your code:
Instead of using containsIgnoreCase uses getPath() and match the path. See example.
Also, for the activity parameter use URL query param instead of containsIgnoreCase. See example
Starting the activity or fragment. I assume startActivity and checkUserAccType will handle that part. See example.
// Else... section should go one line below.
Authentication. It looks fine. And it seems you're using Firebase by the getCurrent method signature. See example

Android studio - Reading whatsapp notifications problem

I'm developing an android app and part of it needs to read WhatsApp messages by the notifications and analyze them.
I'm using a NotificationListenerService and it is working, however, I'm having a problem that notifications are being "analyzed" twice when I get the notification and then get a Message from other chat.
What I want is to analyze each message (Notification) once.
I already tried to save the notification sortKey or the StatusBarNotification key in a HashSet and then check, if it already contains the key every time, however that does not work.
Here is the code that in onNotificationPosted function -
String pack = sbn.getPackageName();
if (pack.equals("com.whatsapp")) {
Bundle extras = sbn.getNotification().extras;
if (extras.getCharSequence("android.text") != null && extras.getString("android.title") != null) {
if (sbn.getNotification().getSortKey() != null) {
String title = extras.getString("android.title");
String text = extras.getCharSequence("android.text").toString();
//Checking if it's from specic group and analyzing the message and
//doing what needs to be done, not related to the problem.
}
}
}
The result I want is that every notification will be analyzed once and not get posted again if some other messages arrive in other chats
Without knowing the inner workings of WhatsApp, it's hard to tell what you should exactly do, because it appears they reuse Actions/Extras for various things (which makes sense anyway).
In this case though, you could keep a list/map of the ones you've already "analyzed" and if you get it again, discard it.

Clear Data Of All the Applications from Your Application (Launcher)

I have created an application which is working as a launcher. In that application I have opening various other apps. In that app I want to clear all the data(i.e login details, search history) of other application to be removed on click of a button.
PackageManager pm = getPackageManager();
Method[] methods = pm.getClass().getDeclaredMethods();
for (Method m:methods){
if(m.getName().equals("freeStorage")){
try{
long desiredFreeStorage = Long.MAX_VALUE;
m.invoke(pm,desiredFreeStorage,null);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
Using the above code, I am able to delete the cache but not able to delete the data of other apps.
Please provide me a solution for that.
Sorry for my bad english.
Its normal behavior. you can't delete data that belongs to other Apps via your app. Files that contain data are private and only accessible by Apps that own them or shared by App.
For example, most of the Apps use SharedPreference as private files to save data for later use. So, its senseless if other Apps are allowed to delete that data.

How to access data of another firebase project

I created real time database on firebase, from one android app im sending data and in other app(second separate app different from the app im using for send data, for just retriving if there is change in data) i want to receive that data, how can i do this, because if I'm trying to access like this in onCreate
FirebaseApp.initializeApp(this);
DatabaseReference data = FirebaseDatabase.getInstance()
.getReference("https://my-project.firebaseio.com/nodeName");
I'm getting first initialzeApp also i tried with adding google-service.json from my app that sending data, its saying that its different from project name, how can i do that the firebase structure is like this
{ https://my-project.xxxx somenumbers
{
node{
lat : "value"
lng : "value"
}
}
}
For every Android app that you create in Android Studio that you want to use with a specific Firebase project, you should create an Android app in the Firebase console too. You can do this by going to the overview page of your project and clicking "Add another app".
In Firebase console there is option to add multiple apps in the same project. All applications that belong to same project can access same Firebase database. Each app has its own .json file connected with same project. So, if you want to access database from any other app then you need to connect that app with the same Firebase project at the console. And to get the values, make a reference to node and apply value change listener to it. Official documentation will help you
Your code should be like this
DatabaseReference otherDB_data = FirebaseDatabase
.getInstance("https://my-project.firebaseio.com/nodeName")
.getReference();
instead of
DatabaseReference otherDB_data = FirebaseDatabase.getInstance()
.getReference("https://my-project.firebaseio.com/nodeName");
and Don't forget to authenticate in your app to get realtime database access
Note: Authenticating is useless if Realtime Database Rules are like
{
"rules": {
".read": "auth == null",
".write": "auth == null"
}
}
so everyone already have the permission
You can do this as many times as you like, but you can only have one
connection to any given database instance at once.
Source : Firebase Documentation - Connect your app to multiple database instances

Categories

Resources