Get notification info - java

I make the notification display and encounter a problem - some notifications do not have a title and text, for example, a player, some do not have anything in extras, like CleanMaster's notification about installing the application.
CharSequence title = (CharSequence)nf.extras.get("android.title");
CharSequence text = (CharSequence)nf.extras.get("android.text");

Related

Web-push notifications without a title don't appear

The PWA Web-push notifications for Android aren't appearing without a title set (body only).
I have a bug that an Android push notification is not multiline.
All the text is set in the notification's title - no surprises.
Splitting the text is kinda difficult as there are really a lot of options with their own variables and localization.
I've tried to set the text into a body instead of a title as it's done for iOS (working fine), and the notification just won't come!
webPushBuilder = new WebPush.Build()
.addBody(localizedText)
.addData(customDictionary);
The pushes arrive with title only and with title+body, but body-only ones don't come.
Is there a way to send them without the title?
From what I found, a title is required to receive a Push notification on Android.
Setting title to "\n", " ", "" won't work either.

make certain text from sms able to pop up copy option on android

I send sms using java with smslib library, that contain code that i want to copy when sms received from my android device.
here is my code
String stringMessage = "code : xxxxxxyyyyyzzzzzz \n"
+ "any question : http:/sitamvan.com";
String number = "08888888888";
OutboundMessage msg = new OutboundMessage(number, stringMessage);
Service.getInstance().sendMessage(msg);
for example the text on the sms will be like this
code : xxxxxxyyyyyzzzzzz
any question : http:/sitamvan.com
when i received the sms (i opened it with default sms app), the url is blue in color and can be copied just by tap on it and the copy option will be popped up.
is it possible to make my code blue in color too? so the default sms app read my code as some copyable text just like when number or link is present on it? may be by adding some text or enclose it with apostrophe?

How do I change the text shown in GooglePlayServicesUtil.getErrorDialog()?

I am trying to follow the gcm tutorial from Googles docs. They say to call this method if Play Services are out of date:
GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000).show();
That's fine, but it puts a dialog that says "This app won't run unless you update Google Play Services" with an "Update" button. I want to change the title and the message text. My users CAN skip the update, and the app will still run. They just won't get push notifications. How do I change the message of the dialog?
I would like to do something like:
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000);
errorDialog.setTitle("out of date");
errorDialog.setMessage("Please update or push notifications won't work. Thank you");
errorDialog.show();
You can override desired string value in your application's strings.xml like this. Simply add these lines in your strings.xml
For message on dialog
<string name="common_google_play_services_update_text" msgid="448354684997260580">This app won\'t run unless you update Google Play services.</string>
For title on dialog
<string name="common_google_play_services_update_title" msgid="6006316683626838685">out of date</string>
EDIT
You could find more information here
http://blog.elsdoerfer.name/2010/04/08/android2po-managing-android-translations/
and What's the meaning of attribute 'msgid' in strings.xml?
msgid is used in android internal strings for localization but I never found any documentation about it. Two reference I have as above. I believe if you remove the msgid still it would work, although I never tried it.
The source of this code is
android_sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\common_strings.xml

How to disable default Android NFC app when NFC is used in my app [duplicate]

This question already has answers here:
Android app enable NFC only for one Activity
(2 answers)
Closed 3 years ago.
In my app I am using NFC to read tags. I click on the button to enable NFC. A progress dialog is opened to read the NFC tag, and when done, NFC is disabled. That's all working fine. But when NFC is not enabled in the app and I put a NFC tag to the phone, the default Android app reads the NFC tag and puts my app to the background.
How can I disable the Android app?
My code for enabling / disabling NFC:
/**
* #param activity The corresponding {#link Activity} requesting the foreground dispatch.
* #param adapter The {#link NfcAdapter} used for the foreground dispatch.
*/
public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
IntentFilter[] filters = new IntentFilter[1];
String[][] techList = new String[][]{};
// Notice that this is the same filter as in our manifest.
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
filters[0].addCategory(Intent.CATEGORY_DEFAULT);
try {
filters[0].addDataType(MIME_TEXT_PLAIN);
} catch (IntentFilter.MalformedMimeTypeException e) {
throw new RuntimeException(activity.getString(R.string.exception_wrong_mime_type));
}
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
/**
* #param activity The corresponding {#link MainActivity} requesting to stop the foreground dispatch.
* #param adapter The {#link NfcAdapter} used for the foreground dispatch.
*/
public static void stopForegroundDispatch(final Activity activity, NfcAdapter adapter) {
adapter.disableForegroundDispatch(activity);
}
You can't disable this behavior. Another app is launched because your app doesn't catch the tag. When you delete the app this will stop, but ofcourse that's not the solution.
If you want to prevent this you should catch the scanned tag in your app, which is on the foreground.
You already know how to do this with enableForegroundDispatch. Don't disable the foreground dispatch when a tag is scanned, but create a flag or something which determines if you want to do something with the tag or not.
For example:
Create an attribute e.g. doSomethingWithTheTag
Add a condition to your tag handler that doSomethingWithTheTag should be true. If it's false don't do something with the tag. In most cases, this will be your onNewIntent override, just make sure every activity overrides that function.
When your dialog opens set the doSomethingWithTheTag to true
Read the tag and handle it
Set doSomethingWithTheTag to false
If you scan a tag now, it will be catched by your app, but nothing will happen.
Hope i'm clear. Good luck!
I was getting the same problem, in my phone there was 2 nfc enabled app installed. Whenever i start my app instantly default app opens, for this i create a BaseActivity and extend it in my all activities and there i overrided both methods
adapter.disableForegroundDispatch(mainActivity);
enableForegroundDispatch()
and i have onNewIntent(Intent intent) method only interested activity and i have a check like
#Override
protected void onNewIntent(Intent intent)
{
if (!isThisDialogWindow)
handleIntent(intent);
}
so i get rid of opening of default app when my app running.
Note But i have still one issue sometimes still opening other app when my app running. Please genius look into this :-)
I think I figured out a simple solution which is when you create your PendingIntent, for the 3rd argument simply put new Intent(). So:
if (pendingIntent == null) {
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
}
And then set your NFC adapter as:
adapter.enableForegroundDispatch(this, pendingIntent, null, null);
Do this in all of the activities in which you don't want anything to happen in your own app when you scan an NFC tag (though it will create a sound), and you also don't want the default Android NFC reader to pop up.

Clear intent action default

I am launching the camera app in normal or secure mode depending on what gesture is performed using my app but once the user selects the app and taps Always then there is no option to change the defaults, even from the settings menu in Android.
camera_intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
secure_camera_intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
camera_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
secure_camera_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
this.startActivity(camera_intent);
//this.startActivity(secure_camera_intent);
Is there a workaround? I want to show the camera selection dialog once again so that the user can change his choice.
If you want to present the app chooser even if the user has a default activity selected for the task, use Intent.createChooser().
From the Android developer guide:
If you call Intent.createChooser(), passing it your Intent object, it
returns a version of your intent that will always display the chooser.
This has some advantages:
Even if the user has previously selected a default action for this intent, the chooser will still be displayed.
If no applications match, Android displays a system message.
You can specify a title for the chooser dialog.
You should also check the documentation for ACTION_CHOOSER for guidelines on where this is appropriate or not (Intent.createChooser() is just a convenience method for this).
startActivity(Intent.createChooser(senderIntent, "Title here"));
It will always display the chooser dialog.

Categories