Comments (10)
@Xuejiao-Shi
I fixed the problem by writing AGConnectApp.Create
code at start of the application and use DefaultInstance
.
Now am able to send notifications from my C# project.
Thanks for your valuable time and help.
from hms-push-serverdemo-csharp.
This issue may be caused by repeated creation of AGConnectApp.
similar question for you reference, but it's in Chinese, you can translate it:https://developer.huawei.com/consumer/cn/forum/topic/0201691801128470750?fid=18
from hms-push-serverdemo-csharp.
But am creating AGConnectApp to access my account,
from hms-push-serverdemo-csharp.
Can I confirm what changes you made in the project after you downloaded the demo?
from hms-push-serverdemo-csharp.
I have Just added AGConnectAdmin SDK to my solution and added AGConnectAdmin Reference.
And try to send notification from my project using above method.
from hms-push-serverdemo-csharp.
This error may be caused by the repeated creation of AGConnectApp.
This is the code for throwing an exception because the AGConnectApp already exists. You may have created AGConnectApp in other places besides the code in the screenshot which you provided. You can search for the create keyword to locate the fault.
from hms-push-serverdemo-csharp.
@Xuejiao-Shi
Am sure, am creating AGConnectApp only at one place. That is inside SendTestMessage().
If possible, can you test it from your end with below code please.
`
public async Task SendTestMessage()
{
var response = "";
try
{
var ag = AGConnectApp.Create(new AppOptions()
{
ClientId = "",
ClientSecret = ""
});
var msg = AGConnectMessaging.GetMessaging(ag);
await msg.SendAsync(new Message()
{
Notification = new Notification()
{
Title = "Test Message",
Body = "Detail Message",
},
Android = new AndroidConfig()
{
Notification = new AndroidNotification()
{
Title = "Notification from .NET",
Body = "Hello world!",
ClickAction = ClickAction.OpenApp()
}
},
Token = new List<string>() { "" }
});
} catch (Exception ex)
{
response = ex.Message.ToString();
}
return response;
}
`
from hms-push-serverdemo-csharp.
Can you delete the code for creating AGConnectApp and check whether the error persists?
from hms-push-serverdemo-csharp.
Am getting Object reference not set to an instance of the object
exception when used below code.
`await AGConnectMessaging.DefaultInstance.SendAsync(new Message()
{
Notification = new Notification()
{
Title = "Test Message",
Body = "Detail Message",
},
Android = new AndroidConfig()
{
Notification = new AndroidNotification()
{
Title = "Notification from .NET",
Body = "Hello world!",
ClickAction = ClickAction.OpenApp()
}
},
Token = new List<string>() { "IQAAAACy0uRmAAAvsZe3QA42M8KS-3Dg6Dyqubcc8cTUIj-PW7tV0z82aiuXXNoNR_n_XV9HZ0BUa9VtkAi-OUNGxXN_rLYNbhgad5mgfBvdirxssQ" }
});`
from hms-push-serverdemo-csharp.
@Xuejiao-Shi
Am using above code in ASP.net Webapi project,
Do i need to initialise below code some where else and access ag
?
var ag = AGConnectApp.Create(new AppOptions()
{
ClientId = "",
ClientSecret = ""
});
from hms-push-serverdemo-csharp.
Related Issues (3)
- Demo 发送的通知栏消息没有声音,没有横幅 HOT 5
- Batch Send支援 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hms-push-serverdemo-csharp.