We are localizing our app to be able to easily switch between languages. Everything works nicely except for some cached values that are actually in navigation. We have two options:
completely restart app on language change - in this case I need a notification and force restart
just load new strings into the table - in this case it will require to replace string values and rbuild custom navigation state.
IN both cases we need a way to find out when language switches. Is there an intent we can listen to? If yes could you please advise on which one? I am thinking to go with a broadcast receiver. I am just not sure which intent action it is. In below example what is the SOME_ACTION value?
Thanks in advance.
<receiver android:name="com.v1.application.notifications.LanguageChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.SOME_ACTION" />
</intent-filter>
</receiver>
android.intent.action.CONFIGURATION_CHANGED
Related
Here's the use case: I want to create a statistics tool that lists all incoming push messages on a given phone, their message text, when they arrived and their source. clarification: I need 100% access to the data as I'm creating my own presentation tool for private use. It's not to be a consumer app.
I'm thinking I can achieve this by creating an app that somehow listens to all incoming intents of type com.google.android.c2dm.intent.RECEIVE and then analyzing the contents of those. Now I believe that is not possible with the security and intent model of stock Android. But is there anyway around this either with a stock rooted phone, or do I even have to go further and fork and modify AOSP?
Other options I can think of is to monitor the visual notification center itself, if that has an API (which I doubt).
Any suggestions are welcome. I am not intimidated by difficult tasks. Yet my knowledge is limited to Java Android coding - I know little of AOSP or the NDK, but I'd be willing to learn if this is the path I must take.
(Sorry if this is a very broad question, I'll accept the answer that gives me the easiest path to a solution)
So it turns out it wasn't all that difficult. You need an app with minSdkVersion=18 and then you can implement a NotificationListenerService which listens for created or deleted notifications, or you can poll for the currently visible.
Caveat: You need explicit persmission from the user to read notifications other than your own.
Basically what you do is 1. Extend the NotificationListenerInterface and override the onNotificationPosted like this:
#Override
public void onNotificationPosted(StatusBarNotification notif) {
Bundle extras = notif.getNotification().extras;
String packageName = notif.getPackageName();
if (extras != null) {
String title = "" + extras.getCharSequence(Notification.EXTRA_TITLE);
String description = "" + extras.getCharSequence(Notification.EXTRA_TEXT);
// Do whatever you want to do with the data
}
}
In addition you need to register the service in the manifest:
<application>
<!-- (...) -->
<service android:name=".YourListenerClassName"
android:label="#string/app_name" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>
I am using the Cast Companion Library and it is mostly working fine, I get the mini player, and also the lock screen controls and the activity for playing content, but I can never get the notification screen to show. I am doing the following when initializing:
mCastMgr.enableFeatures(VideoCastManager.FEATURE_NOTIFICATION |
VideoCastManager.FEATURE_LOCKSCREEN |
VideoCastManager.FEATURE_DEBUGGING);
and I am doing the incrementUiCounter() on resume and decrementUiCounter() on pause.
I don't see any errors, I just don't see what I am doing wrong. The only thing I am missing is that I am not passing URLs for images when telling media to play because my URLs are local assets to my app and I'm just not sure how to pass those.
Are you using that with your own app or with CastVideos-android? If your own app, first I suggest you try the CastVideos-android app to make sure that works for you.
I suggest you print out the value of mVisibilityCounter in BaseCastManager.incrementUiCounter() and decrementUiCounter() to see if as you move in and out of different activities, it reflects the correct counter. When that counter reaches zero, then notification should show up. If the counter is reaching zero and the notification doesn't show up, I suggest you check your manifest file and see if you have the following in your Manifest:
<service
android:name="com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.sample.castcompanionlibrary.action.toggleplayback" />
<action android:name="com.google.sample.castcompanionlibrary.action.stop" />
<action android:name="com.google.sample.castcompanionlibrary.action.notificationvisibility" />
</intent-filter>
</service>
(you can copy-and-paste from the CastVideos-android manifest file). You may have grabbed what it is from the documentation; there is an error there (I am planning to update a bunch of things tonight or tomorrow and the documentation will be updated as well); basically when the counter reaches zero, it calls into the notification service (see the onUiVisibilityChanged() in VideoCastManager) and if that action in manifest is not correctly set, the notification never gets our memo! Let me know if that is not the issue.
I had the same trouble. Just an FYI to those looking at this in 2016. The manifest entry is now different. I suggest to grab whatever is in the manifest of the CastVideos-android project.
<receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" />
<service
android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" />
<service android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService"/>
Hello my question is a bit difficult let me explain and try to understood
I have a custom Home who is set as default when user press home. Know i need a way to ask wich home use when i press on a setting key, or a way to launch Setting activity for delete home default action.
In fact i wan't a way to go back to home app installed by google instead of mine just in case.
I need this because my custom home is still in dev and don't have all feature yet.
I need to keep my home as a default action when user press home buton but i need to add a home selector in special case.
I have try to use finish() when i need to go back to old home but mine as default is automaticly relaunch because he is the default one.
Any idea?
EDIT
I try to reformul a bit.
I'm making a home apps. I set it as default on my tablet. My home apps don't have all feature yet. And when i will launch something or go to setting i need to relaunch default home app.
So i need a way inside my app to reset default home action or launch a home apps, or ask user to choice wich app he will use has home apps.
Hope this is clear for all.
Probably you should use this one to implement your idea. keep the below lines in your manifest file.
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more info about the sample project. just go the below path in your Android SDK
\android-sdk\samples\android-8\Home
EDIT :
Hi Please check this to pro grammatically unset the default application.
How do I use PackageManager.addPreferredActivity()?
for more info go through this also to clear the clearPackagePreferredActivities
http://developer.android.com/reference/android/content/pm/PackageManager.html#clearPackagePreferredActivities%28java.lang.String%29
hope this helps you.
i have an application which associates pdf files in my Manifest(via intent-filters), so when someone click on pdf link in the default browser i can execute that action with my app and download it with a progressbar. my question is, is it a way that i can associate other files but not "hard coded" in my manifest, but to let the user choose(or write) that file extention in preferences for example and i can add it dynamically from code. i know that probably this can be done with broadcast receiver but cant find any examples or simple code for that matter. ive seen preference menu like that in bsplayer settings .. but cant post image cuz dont have enough reputation.
I will try to explain more detailed my problem, because i think that there was some misunderstanding with the answer below.
i have an application which have the fallowing code in my manifest.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
2.i launch my app which registers .pdf files with it. so next time i click on pdf link in my browser, a window pops up, making me choose with what application should i complete that action. if i choose my application, my main activity is launched, in which i use getIntent() and my app downloads the file using progressbar.
3.the problem is that i want to download and other files like that ie. jpg, png .. etc, but giving the user a choice which ones, or even making him write the extentions for the files he wants to download using my application if clicks on link somewhere that leads to that kind of files.
4.to make this thing happen, file extensions should be added dynamically in code somewow and not in manifest. i was looking some examples for broadcast receiver, since that class can use IntentFilter class, but cant really understand what i should be doing with it.
5.My main goal: starting my app, there is layout with some spinner or edit box. the user choose/writes some extension (.dwf). that extension is now registered with my app. if the next time the user browsing internet clicks on link which leads to .dwf file he could choose to continue the action with my app. and the file should be downloaded just like the .pdf
6.sry for my bad english and some help will be appreciated. also code ;)
boolean enabled=prefs.getBoolean(key, false);
int flag=(enabled ?
PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
ComponentName component=new ComponentName(MyActivity.this, TargetActivity.class);
getPackageManager()
.setComponentEnabledSetting(component, flag,
PackageManager.DONT_KILL_APP);
Depending upon your preference you can Disable the activity that handles the File type in your BOOT_COMPLETED Reciever. I Believe you will have to have different activities to handle different file types and then disable selectively
The documentation says you can specify a custom category.
When, why and how would you do it?
What would be the use of it?
The way I understand it, categories are public directives to the android operating system(and other apps) that represent different categories that your app should be a part of.
Example
When the launcher icon is tapped on the home screen, the home application looks through every installed app's manifest for the HOME category -- and if so it displays it in the app drawer.
However, there's more. You can specify categories in your applications manifest that lets the system know that you application can handle the intent category. For example, by putting a ALTERNATIVE category, other apps in the system know that your app can handle that category without specifically knowing the action name! In the following example, custom intent categories are passed through this intent, which is filtered and the corresponding object gets edited(taken from the Notes example app):
<intent-filter android:label="#string/resolve_title">
<action android:name="com.android.notepad.action.EDIT_TITLE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.ALTERNATIVE" />
<category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
By registering this intent filter in an <activity /> tag, you can edit a "note". The intent data would contain the note, and the intent would get routed to the activity that this filter is registered in.
In Conclusion:
There isn't really a reason you'd use a custom category. They are for Android, and thus don't really make sense in application use. But, if you choose to use them, they can be used in the methods described above. "They provide some specific semantic rules, and if those rules are useful to you then feel free to use them"(Hackbod).
http://developer.android.com/guide/topics/intents/intents-filters.html
Scroll down a bit and you should see a section under "Intent Objects"
They basically describe certain special properties of an activity. for example, adding
<category android:name="android.intent.category.HOME" />
means that the app can be started on the phone's bootup
I'm kinda a noob to Android still, although I have programming experience otherwise.. It says a custom category in your own namespace. I'm guessing that if you are programming multiple apps and you want one app to run another app, you could use a custom category for your intent to force the phone to find your other app to catch the intent with?
When you do not want to use the default category then use the custom category.
Custom categories should use the package name as a prefix, to ensure that they are unique.
Some information is provided on below link:
http://developer.android.com/guide/topics/manifest/category-element.html
Check the below link it has somewhat same question:
Android custom categories