Android Unable to open Spotify app programmatically - spotify

I have installed Spotify app in my android phone.
Below code was not able to launch or open Spotify app programmatically. Please help.
Android Intent:
PackageName: com.spotify.music
ActionName: android.intent.action.VIEW
val intent = Intent(Intent.action.VIEW)
intent.setPackage("com.spotify.music")
if (intent.resolveActivity(packageManager) == null) {
Toast.makeText(this,"Please install Spotify App first.",Toast.LENGTH_SHORT).show()
return
}
startActivity(intent)

To open any application using the package name, you can follow this: https://stackoverflow.com/a/7574735/4566483.
For Spotify:
val launchIntent = packageManager.getLaunchIntentForPackage("com.spotify.music")
if (launchIntent != null) {
startActivity(launchIntent)
}

Related

how to implement flutter web local notification?

I'm wondering if I can implement local notification in flutter web? I saw that I can create local notification for mobile app Android or IOS but is it possible to use it for web app? or any other alternative to accomplish it?
Just use the class Notification in dart:html package. You can do something like this:
import 'dart:html' as web;
Future<void> showNotification( String message ) async {
var permission = web.Notification.permission;
if (permission != 'granted') {
permission = await web.Notification.requestPermission();
}
if (permission == 'granted') {
web.Notification( message );
}
}
More info about the javascript notification API here: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API

How to communicate between native and native web view running a flutter's web app?

Android allows specifying a Javascript interface to act as a bridge between the webview and Android code. Similarly, iOS provides the UiWebView stringByEvaluatingJavaScriptFromString method that allows communicating with the underlying webview.
But the issue is that once we build the flutter web app and say we include it as part of a web view in android , Then whenever communication needs to take place , there is some amount of code that we should write in both android side and javascript side manually.
Since editing javascript code generated from flutter web app build is impractical , we need a way to establish a communication channel on flutter side which will talk to the native side using the same type of javascript bridge above. This will be something similar to the method channels when using the flutter app on the native side directly.
So how would we inject or add our custom javascript code from inside flutter so that it will be added during compiling the js file ?
You can create a webmessage channel on the android side (iOS has an equivalent).
There is a description of how to do it here:
How Do You Use WebMessagePort As An Alternative to addJavascriptInterface()?
A brief setup on the javascript side looks like this - you would need to implement this in dart html:
const channel = new MessageChannel();
var nativeJsPortOne = channel.port1;
var nativeJsPortTwo = channel.port2;
window.addEventListener('message', function(event) {
if (event.data != 'capturePort') {
nativeJsPortOne.postMessage(event.data)
} else if (event.data == 'capturePort') {
/* The following three lines form Android class 'WebViewCallBackDemo' capture the port and assign it to nativeJsPortTwo
var destPort = arrayOf(nativeToJsPorts[1])
nativeToJsPorts[0].setWebMessageCallback(nativeToJs!!)
WebViewCompat.postWebMessage(webView, WebMessageCompat("capturePort", destPort), Uri.EMPTY) */
if (event.ports[0] != null) {
nativeJsPortTwo = event.ports[0]
}
}
}, false);
nativeJsPortOne.addEventListener('message', function(event) {
alert(event.data);
}, false);
nativeJsPortTwo.addEventListener('message', function(event) {
alert(event.data);
}, false);
nativeJsPortOne.start();
nativeJsPortTwo.start();
A similar solution for listening over using an eventlistener on the window in flutter web is below:
window.onMessage.listen((onData) {
print(onData.toString());
MessageEvent messageEvent = onData;
for (Property property in properties) {
if (messageEvent.data["id"] == property.id) {
});
} else if (messageEvent.data["northEastLng"] != null) {
print(messageEvent.data["northEastLat"]);
if (double.parse(messageEvent.data["northEastLat"]) == bounds.northEast.lat && double.parse(messageEvent.data["northEastLng"]) == bounds.northEast.lng){
return;
}
LatLng southWest = new LatLng(double.parse(messageEvent.data["southWestLat"]), double.parse(messageEvent.data["southWestLng"]));
LatLng northEast = new LatLng(double.parse(messageEvent.data["northEastLat"]), double.parse(messageEvent.data["northEastLng"]));
LatLngBounds incomingBounds = new LatLngBounds(southWest, northEast);
if (incomingBounds == bounds) {
return;
}
bounds = incomingBounds;
_propertyListPresenter.filterBounds(bounds);
}
}
});

Welcome message Bot Framework v4 nodejs

I'm developing a multichannel bot (focusing on web and telegram) that's based on Microsoft's Bot Framework (https://learn.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0)
I'm stuck with the initial message the user is getting.
My bot is based on the complex bot published by Microsoft: https://github.com/Microsoft/BotFramework-Samples/tree/master/SDKV4-Samples/js/complexDialogBot
Issue I'm seeing is that in the emulator bot is working great, on the web user is not greeted with the welcome message. I've used iframe to integrate the bot.
I'm checking activity types and when members are added to the chat, but seems like it's not triggering on the web.
if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
if (turnContext.activity.membersAdded && turnContext.activity.membersAdded.length > 0) {
await this.sendWelcomeMessage(turnContext);
}
}
I saw similar questions asked but either for bot framework v3 or C# implementation (like this one Welcome message not visibile in Webchat,but work in Emulator and Welcome Message not working in Azure portal using Microsoft Bot Builder SDK(v4) for nodejs)
try using this
enter code here
this.onMembersAdded(async context => {
const membersAdded = context.activity.membersAdded;
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
if (membersAdded[cnt].id == context.activity.recipient.id) {
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
}
}
});
You can solve your problem in below code
in iframe to integrate the bot you can write member Adding code copy in inside !turnContext.responded
if (turnContext.activity.type === ActivityTypes.Message) {
if (!turnContext.responded) {
await this.sendWelcomeMessage(turnContext);
}
}

Port Admob to mobile web

I am in the depths of creating a mobile web game that I will soon release. I am interested in monetizing this app. I want the game to feel like its a regular app and therefore wish to have admob ads (with deep links to the app store). I have heard that these also have substantially higher cpm that adsense mobile. My question is this: if I "port" admob using node.js will the clicks and views be recorded as server side, i.e. coming from one place, or mobile, i.e. from the user?
Here are some resources I am thinking of using:
https://media.admob.com/api/v1/docs/
https://github.com/floatinghotpot/cordova-plugin-admob
Any thoughts?
I am the author of the plugin you mentioned: https://github.com/floatinghotpot/cordova-plugin-admob
The basic version has been deprecated, and the pro version is recommended: https://github.com/floatinghotpot/cordova-admob-pro
Instead of porting AdMob to mobile web, you can consider use Cordova to pack your html5 game as a hybrid APP, then publish to Apple AppStore or Google Play Store.
Use the AdMob plugin to present Ad in your app, then Google will pay you.
Only a few javascript lines to present the Ad, and the AdMob SDK will take care of Ad presenting and user click.
See the example code:
function onLoad() {
if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}
}
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
}
// it will display smart banner at top center, using the default options
if(AdMob) AdMob.createBanner( {
adId: admobid.banner,
position: AdMob.AD_POSITION.TOP_CENTER,
autoShow: true } );

push notification in windows phone 8

Hello friends i am following this Push notification link and able to implement it . it is working but i tried to change the CurrentChannel name from MyPushChannel to Channeltest then it is not able to create new channel and throwing exception of invalidOperation type will you guys please explain me why it is happening here is the code..
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("Channeltest");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("Channeltest");
CurrentChannel.Open(); // exception comming here
CurrentChannel.BindToShellTile();
}
}
In Windows Phone, you have a restriction per application of one push channel. If you want to change the name, uninstall the app from the device/emulator and make the deployment again. It should work.

Resources