Android Studio connect with existing SQLite database - android

i have one application with SQLite database and then i create another application that can connect to the database that i created one, my question is, is it possible connect the existing database without copying the existing once ? if possible can any one give me a sample code to connect my existing database . the name of my database is "SEIS" and the Table is Proinfo .

By default, each app's files are private to the app.
You could tell Android that your two apps should get permission to access each other's files by setting the sharedUserId attribute for both and signing them with the same signature, but the 'official' way to give other apps access to your data is to create a content provider.

Yes it is possible through the use of content providers. According to the documentation:
A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.
I suggest you read the following articles:
http://developer.android.com/guide/topics/providers/content-providers.html
http://www.tutorialspoint.com/android/android_content_providers.htm

Related

Android Sqlite Database is modifiable outside my app?

Is it possible to update SQLite database of android app outside app?I mean can user modify database according to them where the database situates in default location?
The default location is in /data/data/your-package/databases which is only accessible from your application. No other application is able to access it.
However in some special cases like rooted device, debug mode etc , it is still possible to access the database file and change it.
You can access the DB using Content Provider if you want to access it programmatically. Or If you just want to browse the data then you can follow this post.

What is a ContentProvider and what is it typically used for?

i'm beginner in android development, need help regarding ContentProvider.
public class My Application extends ContentProvider {}
A ContentProvider manages access to a structured set of data. It encapsulates the data and provide mechanisms for defining data security. ContentProvider is the standard interface that connects data in one process with code running in another process.
Kindly refer following links,
https://developer.android.com/guide/topics/providers/content-provider-creating.html
and
https://www.tutorialspoint.com/android/android_content_providers.htm
A content provider component supplies data from one application to others on request. one application cannot directly access (read/write) other application's data. Every application has its own id data directory and own protected memory area.
Content provider is the best way to share data across applications. Content provider is a set of data wrapped up in a custom API to read and write. Applications/Processes have to register themselves as a provider of data.
In simple language you can say content provider is a shared database which expose his properties and on there behalf of them other application can access and store the data as per the implementation privilege
Content providers can help an application manage access to data stored by itself, stored by other apps, and provide a way to share data with other apps. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process. Implementing a content provider has many advantages. Most importantly you can configure a content provider to allow other applications to securely access and modify your app data.
It is not that they are used only to share data with other applications. You may still use them because they provide a nice abstraction, but you don’t have to necessarily share data with other apps. This abstraction allows you to make modifications to your application data storage implementation without affecting other existing applications that rely on access to your data
You can get more info from the documentation.
ContentProvider is mainly used for access data from one application to another application.
For example by using ContentProvider we can get phone contacts,call log from phone to our own application in android.we can also access data which are stored in (sqlite)databases.

How do content providers works?

Well, as far as I kwnow a content provider is a database, and is used to pass data through apps.
But this data can be accessed only in the phone that it was saved? Or if I saved some data using the app with phone1, can I retrieve it using the app with phone 2?
If it can't do the second option, what could I use to do it?
Thanks.
Content provider is not a database. You can think this as a layer between your app and underlying data. The data can be in sqlite database, file or something else. Content provider is very useful to access and store your data to database or file. You need this when you use syncadapter or widgets in your app. Now to answer your question, content provider of your app can be accessed by a different app in your same phone provided you use correct permission. As I mentioned it's not a database, so answer of second question is not. I would recommend you to read about content provider on android developer site to get the basic concepts.
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.

Content Providers or direct database?

I was wondering whether we can use the databases like (contacts.db, mmssms.db) directly instead of content providers ?
I have a reason to ask so. In my recent project, I was supposed develop a contact app. I used content provider for contact management. As I have learnt via content providers, I can query only table at a time via URIs, there is no way (at least, I didn't find) to join two tables and then get a query resolved.
And I had read, that databases are only visible to the applications that originally created them, so do my app would be able to access these databases ?
I am just a hobby developer for my own phone. I have no intention to make an app that directly uses the databases. I can pull the database from device, analyse them via sqlite. It is not that I am up against the content providers or they don't suit my need write now, it is just that it can be done or not ?
Any opinions ?
Content Providers give you a lot more than just database access. Being able to use Loaders to automatically reload your data (and update your UI) when the underlying data changes can vastly simplify your applications.
The goal of Content Providers is more to create a single, controlled layer for accessing your data. There is nothing stopping you from creating a custom URI that joins multiple tables together and returns the resulting joined result.

In Android, How to monitor other app's sqlite database and update some rows

I want to implement an Android app which can monitor another specific app's sqlite database, and remove some specific rows from a table. The working senaria is as below:
Open a specific social app (for example, twitter), and press
Refresh/LoadMore
The social app sends HTTP request to retrieve
data
The social app parses the result, and insert into sqlite
database
[My App] My app monitors the table changes, and update
some rows
The social app displays records from sqlite to UI (The
rows that my app removes will not be displayed in UI).
Is it possible to develop such kind of app? I understand this app needs root access. But if the app has root access, can I achieve this goal? Thanks.
this is only done when other app have used ContentProvider and the give us Permission for access that.
A ContentProvider can be used internally in an application to access data. If the data should be shared with another application a ContentProvider allows this.
Many Android datasources, e.g. the contacts, are accessible via ContentProviders. Typically the implementing classes for a ContentProviders provide public constants for the URIs.
for more detail check this artical and this two artical from Adnroid Developer one and two

Categories

Resources