Custom notification with Google Cast SDK v3 - android

Ever since the new Google Cast SDK v3 has been out, I've been thinking about migrating to it, as it has a few features I need and I'm always interested in keeping everything as up-to-date as possible. My previous setup used Google Cast SDK v2 + Cast Companion Library. However I've been unable to find a way to provide a completely custom notification in the new Google Cast SDK v3 which prevents me from using it.
With Google Cast SDK v2 + Cast Companion Library I was able to simply subclass the VideoCastNotificationService and override its build method to make a custom notification:
public class MyCastNotificationService extends VideoCastNotificationService {
#Override
protected void build(MediaInfo info, Bitmap bitmap, boolean isPlaying) {
// ... build the custom notification
mNotification = new NotificationCompat.Builder(this)/*...*/.build();
}
}
Then I could register the MyCastNotificationService in my CastConfiguration like this:
CastConfiguration castConfig = new CastConfiguration.Builder(APPLICATION_ID)
/*...*/
.setCustomNotificationService(MyCastNotificationService.class)
.build();
However, with Google Cast SDK v3 I've been unable to find a replacement that works. Here are the results of the bit of research I've done on this topic:
The MediaNotificationService seems to be the component replacing the VideoCastNotificationService, however it does not seem to have a build method or anything similiar.
Both the NotificationOptions.Builder and CastMediaOptions.Builder classes don't seem to have any methods for registering a custom notification service.
The only documented way of customizing the notification seems to be custom action buttons as shown in the Add Media Controls to Notification and Lock Screen section, however I need to create a notification using the RemoteViews API, so this is not sufficient for me.
Has anyone been able to provide a custom notification using the new Google Cast SDK v3? As far as I can tell, this seems unsupported, but I'd love to be proven wrong here. Thanks in advance!

Related

How to create TelephonyDisplayInfo object in android R device

I want to get getOverrideNetworkType() in android Like as Android CA 5G NSA NR but Enable to Create TelephonyDisplayInfo object to get this. I am using this code but get
TelephonyDisplayInfo mTelephonyDisplayInfo;
mTelephonyDisplayInfo = new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
but get error:-
TelephonyDisplayInfo() is not public in android.telephony.TelephonyDisplayInfo. Cannot be accessed from outside package this error.
Comment from Google support:
Although the constructor is public, it's #hide and not a part of the
API surface, so it shouldn't be accessible to developers. To get the
TelephonyDisplayInfo, please use
PhoneStateListener#onDisplayInfoChanged instead. Closing this as
working as intended.

New MessagingStyle on API < 24

I just stumbled upon the new MessagingStyle described here: https://developer.android.com/guide/topics/ui/notifiers/notifications.html (last paragraph)
I investigated further and found such a class also as a NotificationCompat.Style variant.
This is the code I tried:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
.notify(123, new NotificationCompat.Builder(this)
.setContentTitle("Test")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("4 new messages")
.setStyle(new NotificationCompat.MessagingStyle("Me")
.setConversationTitle("Team lunch")
.addMessage("Hi", 123, null) // Pass in null for user.
.addMessage("What's up?", 234, "Coworker")
.addMessage("Not much", 345, null)
.addMessage("How about lunch?", 456, "Coworker")).build());
}
}
This is basically just the default Activity generated when creating a new project and the sample code taken from the linked website.
Now my problem: The extended style is not shown on APIs below 24. I tested on a device with API 23. When running on an emulator with API 24, it works.
The documentation states:
Helper class for generating large-format notifications that include multiple back-and-forth messages of varying types between any number of people.
If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view. [...]
But versions since KitKat do provide large-format notifications.
Is the documentation not clear enough or am I doing something wrong?
Update: this is fixed as of the 25.0.0 Support Library release and NotificationCompat.MessagingStyle now backports much of the styling to previous versions of Android.
Previous answer:
As per this bug report, MessagingStyle currently does not do any special formatting prior to Android N. The bug report is marked as FutureRelease which means that the work is done and it will support pre-N devices with a more rich formatting in a future version of the Support Library.
If you wish to use it now, you can certainly build your own pre-N version of the notification (using a BigTextStyle if the version of Android is less than N for example).
If I am reading the source code correctly, the fallback for pre-24 devices has not been implemented as of the time of this writing. So, at the moment, it gives you something that compiles, and delegates properly to the native implementation on API Level 24+ devices, but will not show the messages on older devices.
Additional note: check your imports and make sure you use the android.support.v7.app.NotificationCompat class
instead of android.support.v4.app.NotificationCompat, because even in 25.2.0, using MessagingStyle with the "v4" builder does not show anything in devices with API < 24.

Xamarin Forms In app billing for Android

I'm making an app where I have to have in app purchases (buying keys that I can further use in the app).
I have looked at this component http://components.xamarin.com/view/xamarin.inappbilling, but I have no idea how I can implement this in xamarin forms. Is there anyone out there willing to help me with this problem? Is there any open source projects with in app purchase that I can look at?
I know its late, but this might help someone:
The way to do achieve this is to create a service and then surface it to a standard interface (as per your requirement) that will be consumed within the forms project.
You can even use MessagingCenter to communicate between Android and Xamarin.Forms project.
FormsPrject:
MessagingCenter.Send<MainPage, string>(this, "BuyProduct", "buyButtonPressed");
AndroidPoject
MessagingCenter.Subscribe<MainPage, string>(this, "BuyProduct", (sender, arg) =>
{
//logic to buy product
}
Hope that helps!!
The question is very vague so I will offer a general answer and some notes that I found important. I am using Visual Studio 2015 with Xamarin Forms 2.3.0.107.
I would use abstraction for this instead of sending messages directly between the projects.
The basic idea is, you will create a public interface in your Xamarin Forms project. Since your Andriod project has a reference to the Xamarin Forms project, it can use this public interface. Then you will implement this interface in your Android project will all of the billing logic. In the Xamarin Forms project. Using the Dependency service we can get the existing instance of the implementation into the Xamarin Forms project. Then, you can code against the interface. This is especially useful if you ever want to do an iPhone or other implementation, because you would never need to make changes to the Xamarin Forms code; you can just plug in new implementations.
It might be a bit out of scope but, be sure to meet all of the Google requirements as far as setting up your developer account and your merchant account and your API account. It is all very confusing and messy.
The Xamarin component in nuget is currently version 1.5. However, the component has a newer published version. You want to use the newer (2.0 or higher) version.
Use the Android SDK manager to install the Google Play Billing Library.
In your Android project, add a reference to Xamarin.InAppBilling and add a Xamarin.InAppBilling component.
The Google object has to live in an Android activity, because you depend on overriding an activity method to complete purchases (I used the MainActivity here and made the google object a static for easy access)
Testing this with Google Play is a hassle. The documentation is confusing because of differences between versions. You cannot use actual product id's until you publish your app. They provide test id's that can be used during testing but they only offer some functionality.
I have made these code examples as minimal as possible to illustrate the concept. You will obviously want to do much more.
Xamarin Forms project
Create an interface:
public interface IInAppBilling
{
void Pay(string productId);
}
Any time you want to use the billing service, you use IInAppBilling billingService = DependencyService.Get<IInAppBilling>(); to get a reference to the device-specific (Android) implementation.
//call this from a button click or whatever
void BuySomething(string somethingId)
{
//Get any IInAppBilling object that is registered with the DependencyService.
IInAppBilling billingService = DependencyService.Get<IInAppBilling>();
billingService.Pay(somethingId);
}
Android Project
Override an activity's OnCreate method and create an InAppBillingServiceConnection:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
public static InAppBillingServiceConnection google;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
google = new InAppBillingServiceConnection(this, "MII...ApplicationKey");
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
Create a class that implements the Xamarin Forms interface we created earlier. It is important not to ignore the assembly: Dependencyannotation at the top. This is what makes the class available to the Dependency service in the Xamarin Forms object:
[assembly: Dependency(typeof(com.myapp.InAppBilling))]
namespace com.myapp
{
class InAppBilling :IInAppBilling
{
public void Pay(string productId)
{
MainActivity.google.BillingHandler.BuyProduct(productId, ItemType.Product, "MyUniquePayload");
}
}
}
Override the activity's OnActivityResult method to finalize purchases:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
// Ask the open service connection's billing handler to process this request
try
{
google.BillingHandler.HandleActivityResult(requestCode, resultCode, data);
}
catch (Exception ex)
{
//log it or something?
}
}

Chartboost Interstitial won't show Ads on Unity

Lately, I have been trying to add static interstitial ads into my Unity game. For some reason, I could not get the system to show anything, or even react to me. After trying to work with the base Chartboost plugin, I tried to match a tutorial that I was following and purchased Prime31's Chartboost plugin and have been using that. However, neither the base plugin, nor Prime31's plugin, seem to be allowing me to show any ads. The code is pretty much done inside a single object, and it seems simple enough.
public class Advertisement : MonoBehaviour {
public string chartboostAppID = "5461129ec909a61e38b1505b";
public string chartboostAppSignature = "672b3b34e3e358e7a003789ddc36bd2bc49ea3b5";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
ChartboostAndroid.init (chartboostAppID, chartboostAppSignature, true);
ChartboostAndroid.cacheInterstitial(null);
}
void OnLevelWasLoaded(int level) {
ChartboostAndroid.cacheInterstitial(null);
if(Application.loadedLevelName == "Network Lobby") {
showAds();
}
}
public static void showAds() {
Debug.Log("Showing ad");
ChartboostAndroid.showInterstitial(null);
}
}
As you can see, it's pretty straightforward. This object is created at the game's splash screen, which appears only once, and it's never destroyed until the program ends. The goal is, whenever I enter the lobby scene, I want to see an ad before going to the lobby's menus. As it is, I do see the log printing "Showing ad", so I know the function is being called. However, nothing appears. Do I need to disable the GUI system first? Is there a step I'm missing?
I have already performed the following steps:
I have created and registered the app with chartboost, as well as double and triple checked the AppID and App Signature.
I have created a publishing campaign and registered it to the app.
I double-checked the orientation and confirmed that it's correct.
I registered this specific device as a test device.
The tutorial showed a call to ChartBoostAndroid.OnStart(), but there was no function like that for me to call. Perhaps that is from an older version?
I emailed Chartboost support and have not heard from them yet. I do not have that much time on this project, so if anyone can offer help, I'd appreciate it.

Android: Google Analytics availability in Google Play Services?

Google Analytics has been announced to become part of the rolling out Google Play Services 4.3, however it is not yet included in the Google Play Services packages list:
http://developer.android.com/reference/gms-packages.html
Any idea when it will become available, and will it be safe to be used straight away, or will it be better to wait for some time to make sure every user has Google Play Services 4.3 already installed?
I've noticed some other differences.
Tracker
To get a new Tracker, use the newTracker() method (accepts both a String value and an int value [for XML configuration]):
googleTracker = gaInstance.getTracker(GA_KEY); // OLD
googleTracker = gaInstance.newTracker(GA_KEY); // NEW
EasyTracker
EasyTracker has now disappeared, so we will have to use GoogleAnalytics.getInstance(this).reportActivityStart(this) as reported by Paito.
Setters
The googleTracker.set() method is no longer available. It has been replaced with more specialised methods, for example:
googleTracker.set(Fields.SCREEN_NAME, null); // OLD
googleTracker.setScreenName(null); // NEW
Event creation
The googleTracker.send() method has also seen some changes.
googleTracker.send(MapBuilder
.createEvent(category, action, label, value)
.build()); // OLD
googleTracker.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.setValue(value)
.build()); // NEW
AppView
It now becomes
googleTracker.send(MapBuilder.createAppView().build()); // OLD
googleTracker.send(new HitBuilders.AppViewBuilder().build()); // NEW
AppViewBuilder
AppViewBuilder has now been deprecated, replaced by the new ScreenViewBuilder class. (thanks Hai Phong for the tip!)
For those who are running into (or have already dealt with) the Dalvik's 64K methods limit, there are now 3K methods that you will be able to get rid of in your application, thanks to this integration.
It's part of the package list now.
I think the basic functionality works something like this...
import com.google.android.gms.analytics.GoogleAnalytics;
#Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
#Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
As per conversation in order to use Easytracker replacement with
GoogleAnalytics.getInstance(this).reportActivityStart(this);
GoogleAnalytics.getInstance(this).reportActivityStop(this);
You need to add your config to AndroidManifest like
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="#xml/analytics_global_config" />
I'm still having to get instance of Tracker to send Events, may be somebody else would have better luck at replacing
EasyTracker.getInstance(mContext).send(MapBuilder....)
The documentation for Google Analytics SDK v4 (now part of Google Play Services) has just been published!
https://developers.google.com/analytics/devguides/collection/android/v4/

Categories

Resources