I'm working on a project in which I want a feature, message us on WhatsApp and for that, I used WhatsApp API using intent.
in 'message us on WhatsApp' feature I'm using 2-3 different numbers and storing it in the list and using random() method to retrieve that number from the list, as I want whenever a user uses that feature he/she has to connect with a different number every time.
but now I want to change those numbers which are stored inside the list.
So how can I change those numbers without changing the actual code every time?
I know it can be achieved using firebase, but I don't have too much idea about firebase.
I can only upload simple text and images on firebase and retrieve them. but how can I upload all these numbers on firebase? and how I can change them every time within a minute
the code I did is like this
public class DashBoard extends AppCompatActivity implements View.OnClickListener {
public CardView wpicon;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
Util.blackIconStatusBar(DashBoard.this, R.color.white);
wpicon = findViewById(R.id.cardview1);
wpicon.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent i;
String num;
String text;
num = ";
text = "I'm interseted in your service";
ArrayList<String> list = new ArrayList<>();
list.add("+91");
list.add("+91");
Random random = new Random();
String rando = list.get(random.nextInt(list.size()));
switch (v.getId()) {
case R.id.cardview1:
Intent intent = new Intent(Intent.ACTION_VIEW);
i = intent.setData(Uri.parse("http://api.whatsapp.com/send?phone=" + rando + "&text=" + text));
startActivity(i);
break;
One way of doing this with Firebase is by using Firebase Remote Config. The idea is generally simple. The remote config represents a list of keys and values. You have to list your data from the Firebase console and publish it. It will be immediately available to your users.
Related
I am working on an android project and I've been trying to use Firebase Firestore collections. Everything seems fine up until the second activity retrieving the intent with the parsed list of watches.
public class MainActivity extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference watchesRef = db.collection("watches");
private List<Watch> watches = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
watchesRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Watch watch = document.toObject(Watch.class);
watches.add(watch);
}
Intent intent = new Intent(MainActivity.this, WatchesActivity.class);
intent.putParcelableArrayListExtra("watches", (ArrayList<Watch>) watches);
startActivity(intent);
} else {
Log.d("MainActivity", "Error getting documents: ", task.getException());
}
}
});
Say I wanted to print out each watch upon retrieval from firstore, it works just fine. When debugging, I can see the list getting filled with the watches. Debugging goes through to the next activity:
Intent intent = getIntent();
if (intent.hasExtra("watches")) {
watches = intent.getParcelableArrayListExtra("watches");
}
Right up until watches = intent.getParcelableArrayListExtra("watches"); I can see the data just fine, then I get this error java.lang.RuntimeException: Parcel android.os.Parcel#f983085: Unmarshalling unknown type code 7536745 at offset 316
KEEP IN MIND: When I clear the list then add static data, it works just fine.
Overall your approach to Android app architecture is suffering here, fetching a potentially large list of data and then attempting to pass it via an Intent to another Activity is an architecture that won't scale well.
It may fail when the parcel data size exceeds 1MB.
It may fail because Watch doesn't use only primitives or hasn't implemented itself well as Parcelable.
It may fail because when the user opens that Activity, the Watch list is so old and out-dated that your updated app crashes.
A better way to architect the app is to have the Activity that you navigate to fetch the data it needs itself.
If/when you use Intents, keep the payloads minimal. Try to pass just a single id with which the recipient can retrieve from local database or fetch from the Internet with.
I already searched how refresh data in recycler view using retrofit library to get data but unfortunately I can't find anything.
Could you please put me on right direction where I can find information.
I got App when customer make order and see order status, how to make when person update order status, example from 0 in 1 in database, so that's mean it's changed value but retrofit only loaded data when status is 0. How to make when App recognice a value is updated in database and show to customer not 0 status but 1.
Thank you so much
private Handler mRepeatHandler;
private Runnable mRepeatRunnable;
private final static int UPDATE_INTERVAL = 2000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRepeatHandler = new Handler();
mRepeatRunnable = new Runnable() {
#Override
public void run() {
//Put the piece of code which is getting data from server.
mRepeatHandler.postDelayed(mRepeatRunnable, UPDATE_INTERVAL);
};
mRepeatHandler.postDelayed(mRepeatRunnable, UPDATE_INTERVAL);
}
You can use DiffUtil, an Android support library utility class, which helps to ease out the process of finding which item changed in a list of data. It helps to calculate the difference between an old list and a new list and trigger updates to list items.
Here is the example link
I am implementing an Android app that is responsible for some data exchange with other services such as credentials. I then want to use that information to automatically fill in the input fields of other applications on the device such as Spotify.
Is there any way to fill the input fields of another app, like the username and password to remove the chore for the user to manually input it?
Also I noticed that at least on iOS, Spotify recognizes 1Password to be installed and displays a small icon next to the input fields with which I can fill the fields from the data stored in 1Password - how is this done as it seems to be another solution to my problem?
Thanks in advance
You might want to implement Autofill Service https://developer.android.com/guide/topics/text/autofill-services.html
There is a ready to use sample app which will get you started https://github.com/googlesamples/android-AutofillFramework
Android will invoke onFillRequest() method giving your service a chance to show autofill suggestions. Here is a sample code from above link:
#Override
public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) {
// Get the structure from the request
List<FillContext> context = request.getFillContexts();
AssistStructure structure = context.get(context.size() - 1).getStructure();
// Traverse the structure looking for nodes to fill out.
ParsedStructure parsedStructure = parseStructure(structure);
// Fetch user data that matches the fields.
UserData userData = fetchUserData(parsedStructure);
// Build the presentation of the datasets
RemoteViews usernamePresentation = new RemoteViews(getPackageName(), android.R.layout.simple_list_item_1);
usernamePresentation.setTextViewText(android.R.id.text1, "my_username");
RemoteViews passwordPresentation = new RemoteViews(getPackageName(), android.R.layout.simple_list_item_1);
passwordPresentation.setTextViewText(android.R.id.text1, "Password for my_username");
// Add a dataset to the response
FillResponse fillResponse = new FillResponse.Builder()
.addDataset(new Dataset.Builder()
.setValue(parsedStructure.usernameId,
AutofillValue.forText(userData.username), usernamePresentation)
.setValue(parsedStructure.passwordId,
AutofillValue.forText(userData.password), passwordPresentation)
.build())
.build();
// If there are no errors, call onSuccess() and pass the response
callback.onSuccess(fillResponse);
}
class ParsedStructure {
AutofillId usernameId;
AutofillId passwordId;
}
class UserData {
String username;
String password;
}
Am developing chat application in android using Firebase with a feature that user can translate its chat to desired language.I put translation selection menu in my Chat class.Now my code is working fine to translate one text using Yandex Key but my question is how can i translate whole chat using the same scenario? Or how to get all messages in one String to Translate them.
My code for translating one message is as below:
case R.id.german:
TranslatorBackgroundTask tbt = new TranslatorBackgroundTask(getApplication());
String translationResult = String.valueOf(tbt.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, message, "en-de"));
textView.setText(TranslatorBackgroundTask.result);
Why not just use List object for storing all texts and execute translation function repeatedly? Some thing like this
List<String> texts = new ArrayList<>();
// pass texts
List<String> translatedTexts = translate(texts);
public void translate(List<String>) {
List<String> resultTexts = new ArrayList<>();
//apply your logic for translating each text with the for each method
return resultTexts;
}
I am creating a finance Android app that will open up and ask the user to add an account. (This will always be static on the page.) On the Main activity, it will have an EditText box next to a Button ("Add Account"). When the Button is pressed, I want a new Object created and it will then be stored into an ArrayList. The List of accounts (as they are added) will then be looped below (with corresponding dynamic buttons to edit the account). This is my practice/unfinished code. It is very raw at this point!
String accountName = (Whatever is in EditText Box)
ArrayList<Accounts> accountList = new ArrayList<Accounts>();
int accountListSize = accountList.size();
(Button on Click) {
Account{accountName} = new Account(); // Not sure how to dynamically name
accountList.add({accountName}) // Not sure how to dynamically name
}
// iterate through finance loop
for(int i = 0; i < accountList .size(); i++)
{
// do stuff - Create Dynamicly Edit and Clear Buttons for each account
}
One of the big issues I am trying to overcome is how to name an Object Dynamically?
Am I over-thinking this process overall and making it harder than it should be? I am going to create a class to handle the account specifics. I eventually have to keep the data stored--so maybe should I scrap the Object orientated style and use SQLite? Shared-preferences?
Any code samples would be great, but I am mostly hoping to find the recommend method I should take.
I would recommend to create an Account object that takes the name in the constructor. For example:
public class Account {
private String name;
public Account( String name ) {
this.name = name;
}
// ... other account related methods here...
public String getName() {
return name;
}
}
Then in your code above:
List<Account> accountList = new ArrayList<Account>();
(Button on Click) {
Account anAccount = new Account( accountName ); // accountName taken from text box.
accountList.add( anAccount );
}
Then to loop through the account list:
for( Account account : accountList ) {
String name = account.getName();
// .. do whatever you need to for each account...
}
Once you have this list of Account objects, you can do anything you need to do with them, such as storing in SQLite DB for later, etc...
Hope this helps...