I know that there are lot of questions about this but I couldn't figure out the solution from those questions.
I am getting null in a token from GCM. many people have done this using class, but I am doing
this in background thread in same class. It returns null in regId.
OnCreate
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.isEmpty()) {
Log.e(TAG, "registering in background");
registerInBackground();
} else {
Log.e(TAG, "Notification Token : " + regid);
user.setNotificationToken(regid);
}
} else {
MyLog.i(TAG, "No valid Google Play Services APK found.");
}
RegisterInBackgroud() if device is not registered before.
private void registerInBackground() {
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
Log.e(TAG, "doing in background");
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
if(gcm != null)
{
Log.e(TAG, "GCM is not null");
}
regid = gcm.register(SENDER_ID);
Log.e(TAG, "token id:" + regid);
msg = "Device registered, registration ID=" + regid;
storeRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
}.execute(null, null, null);
}
I tried to log it bug it display null in regId. what could be the problem in this ?
Some how my app id was not working. Recreating app on google console generated a new id which i used in my project and it started working.
Related
onBeacon ServiceConnect method is to detect the beacon. For lollipop version is detecting for nougat and oreo version beacon not detecting:
public void onBeaconServiceConnect() {
RangeNotifier rangeNotifier = new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, org.altbeacon.beacon.Region region) {
Log.d(TAG, "in didRangeBeaconsInRegion " + beacons.size());
if (beacons.size() > 0) {
Log.d(TAG, "didRangeBeaconsInRegion called with beacon count: " + beacons.size());
for (Iterator<Beacon> iterator = beacons.iterator();
iterator.hasNext(); ) {
Beacon beacon = iterator.next();
if (beaconlist.size() > 0) {
Log.d(TAG, "List Size :" + beaconlist.size());
for (int i = 0; i < beaconlist.size(); i++) {
Log.d("BeaconList ", beaconlist.get(i));
}
}
if (!beaconlist.contains(beacon.getId1().toString())) {
Log.d(TAG,"In get APi");
getApi(beacon.getId1().toString());
beaconlist.add(beacon.getId1().toString());
Log.d(TAG, "Notify in dead state");
Log.d("Notify in dead state", beacon.getId1().toString());
}
}
}
}
};
try {
Log.d(TAG, "I am in startRangingBeaconsInRegion");
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
beaconManager.addRangeNotifier(rangeNotifier);
} catch (RemoteException e) {
e.printStackTrace();
}
}
This is my code can any one give solution for this issue.
Two things to check:
Have you added COARSE_LOCATION permission to your AndroidManifest.xml and added code to successfully obtain that permission from the user dynamically at runtime?
Do you successfully construct a BeaconManager, call bind(...) and verify you get a callback to onBeaconServiceConnect() before starting ranging? If you do not, you will get a RemoteException when you try to start ranging. It is a good idea to log this exception to LogCat with Log.e(TAG, "Not bound to beacon scanning service")
I have been struggling to programatically add a delegate to a user (boss/admin scenario).
After running my test code in the boss sfb client the admin appears as a delegate however, in the admin's sfb client the boss does not appear under the section "people I manage calls for". I verified in the rtc frontend database that the delegation is configured, however the admin subscription record does not list the boss. Below is the code I used to achieve this.
Any ideas why the admin sfb client is not being notified of the new delegation?
Thanks,
Simon
1) add delegate-management
public void SendAddDelegate()
{
string body = string.Format($"<setDelegates xmlns=\"http://schemas.microsoft.com/2007/09/sip/delegate-management\" version=\"1\"><delegate uri=\"sip:admin#example.com\" action=\"add\"/></setDelegates>");
byte[] encBody = Encoding.UTF8.GetBytes(body);
RealTimeAddress rta = new RealTimeAddress("sip:boss#example.com");
System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType("application/msrtc-setdelegate+xml")
endpoint.InnerEndpoint.BeginSendMessage(MessageType.Service, rta, contentType, encBody, SendAddDelegateManagementMessageComplete, null);
}
private void SendAddDelegateManagementMessageComplete(IAsyncResult result)
{
try
{
SipResponseData srd = endpoint.InnerEndpoint.EndSendMessage(result);
logger.Debug($"srd.ResponseCode - {srd.ResponseCode}");
}
catch (Exception exc)
{
logger.Error("Exception SendMessageComplete with message - {0}", exc.Message);
}
}
2) Publish presence
public void PublishRoutingCategory(string delegateUri)
{
//routes not created here for sample brevity
routes.DelegateRingEnabled = true;
routes.Delegates.Add(delegateUri);
routes.SimultaneousRingEnabled = true;
routes.SimultaneousRing.Add(delegateUri);
routes.SkipPrimaryEnabled = true;
routes.ForwardAudioAppInvitesEnabled = true;
try
{
userEndpoint.LocalOwnerPresence.BeginPublishPresence(new PresenceCategory[] { routes }, PublishComplete, null);
}
catch (Exception exc)
{
logger.Error("Unknown error - {0}", exc.Message);
}
}
private void PublishComplete(IAsyncResult result)
{
try
{
endpoint.LocalOwnerPresence.EndPublishPresence(result);
}
catch (Exception exc)
{
logger.Error("Error Publish Complete- {0}", exc.Message);
}
}
i am trying to integrate qr code scanner in my application in android, i am using zxing library BarcodeEye.
i have implemented below piece of code
Intent intent = new Intent("com.github.barcodeeye.scan.CaptureActivity");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
but i am getting a RuntimeException saying that unable to start activity component : android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.github.barcodeeye.scan}
can any one help me where i am going wrong
Thanks & Regards.
Nagendra
You will need to register CaptureActivity Activity in the AndroidManifest.xml
<activity
android:name="com.github.barcodeeye.scan.CaptureActivity"
android:clearTaskOnLaunch="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:stateNotNeeded="true"
android:theme="#style/CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.github.barcodeeye.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Here is how I use BarCodeEye:
private void startScanActivityForResult(Bundle extras)
{
Intent intentScan = new Intent("com.github.barcodeeye.SCAN");
intentScan.setPackage("com.github.barcodeeye");
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intentScan.putExtras(extras);
intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
intentScan.putExtra("RESULT_DISPLAY_DURATION_MS", 1000L);
intentScan.putExtra("SAVE_HISTORY", false);
intentScan.putExtra("PROMPT_MESSAGE", "QR scan http://user:pass#server");
WtcLog.info(TAG, "startScanActivityForResult: startActivityForResult(intentScan=" + intentScan + ", REQUEST_SCAN)");
startActivityForResult(intentScan, REQUEST_SCAN);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
WtcLog.info(TAG, "onActivityResult data=" + WtcUtilsPlatform.toString(data));
Bundle extras = null;
if (data != null)
{
extras = data.getExtras();
}
switch (requestCode)
{
case REQUEST_SCAN:
{
WtcLog.info(TAG, "onActivityResult: REQUEST_SCAN");
if (resultCode == RESULT_OK)
{
WtcLog.info(TAG, "onActivityResult: resultCode == RESULT_OK");
String result = data.getStringExtra("SCAN_RESULT");
extras = validateScan(result);
/// your logic here
}
else
{
WtcLog.warn(TAG, "onActivityResult: resultCode != RESULT_OK; exiting");
// your logic here
finish();
}
break;
}
}
}
private Bundle validateScan(String result)
{
Bundle extras = new Bundle();
String[] userpass;
try
{
URI uri = new URI(result);
String userinfo = uri.getRawUserInfo();
if (WtcString.isNullOrEmpty(userinfo))
{
throw new URISyntaxException(result, "");
}
userpass = userinfo.split(":", 2);
if (userpass.length != 2)
{
throw new URISyntaxException(result, "");
}
String server = uri.getHost();
if (WtcString.isNullOrEmpty(server))
{
throw new URISyntaxException(result, "");
}
extras.putString("server", server);
}
catch (URISyntaxException e)
{
WtcLog.error(TAG, "validateScan: EXCEPTION", e);
extras.putString("error", "uri must be in format \"http://username:password#server\"");
return extras;
}
try
{
String username = URLDecoder.decode(userpass[0], "UTF-8");
extras.putString("username", username);
String password = URLDecoder.decode(userpass[1], "UTF-8");
extras.putString("password", password);
}
catch (UnsupportedEncodingException e)
{
WtcLog.error(TAG, "validateScan: EXCEPTION", e);
extras.putString("error", "username and password must be UTF-8");
return extras;
}
return extras;
}
I want to show the error message on the other page. I got the NullReferenceException, but the query string is set on the page which has error. Would someone tell me what is wrong with my code?
catch (Exception ex)
{
//Dispatcher.BeginInvoke(new Action(() =>MessageBox.Show(ex.StackTrace,"Error!",MessageBoxButton.OK)));
string query=#"/ErrorPage.xaml?msg=" + ex.StackTrace.ToString() ;
Dispatcher.BeginInvoke(new Action(() =>this.NavigationService.Navigate(new Uri(query, UriKind.Relative))));
}
There is the code for showing the error message when the page is loaded on other page
public ErrorPage()
{
InitializeComponent();
string msg = NavigationContext.QueryString["msg"].ToString();
lstMessage.Items.Add(msg);
}
I should put my code into the MainPage_Load method. It works.
public ErrorPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject,
"Report Error", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
//according to the serach it works on real devices (not on the emulator)
//the reason the EmailComposer not pop up because can't set up an email account on the emulator
EmailComposeTask emailcomposer = new EmailComposeTask();
emailcomposer.To = CMSPhoneApp.App.GlobalVariables.reportAddress;
emailcomposer.Subject = CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject;
emailcomposer.Body = CMSPhoneApp.App.GlobalVariables.errorMsg;
emailcomposer.Show();
}
else
{
App.GoBack();
}
}
Hello I have no idea where I should start looking. I add few prop (before that my code run fine), then I get
System.Diagnostics.Debugger.Break();
so then I comment that changes, but that didn't help.
Could you suggest me where I should start looking for solution?
MyCode:
namespace SkydriveContent
{
public partial class MainPage : PhoneApplicationPage
{
private LiveConnectClient client;
FilesManager fileManager = new FilesManager();
// Constructor
public MainPage()
{
InitializeComponent();
}
private void signInButton1_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
{
if (e.Status == LiveConnectSessionStatus.Connected)
{
client = new LiveConnectClient(e.Session);
infoTextBlock.Text = "Signed in.";
client.GetCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(OnGetCompleted);
client.GetAsync("/me/skydrive/files/");
fileManager.CurrentFolderId = "/me/skydrive/files/";
}
else
{
infoTextBlock.Text = "Not signed in.";
client = null;
}
}
void OnGetCompleted(object sender, LiveOperationCompletedEventArgs e)
{
//Gdy uda nam się podłaczyc do konta skydrive
if (e.Error == null)
{
signInButton1.Visibility = System.Windows.Visibility.Collapsed;
infoTextBlock.Text = "Hello, signed-in user!";
List<object> data = (List<object>)e.Result["data"];
fileManager.FilesNames.Clear();
filemanager.filesnames.add("..");
foreach (IDictionary<string,object> item in data)
{
File file = new File();
file.fName = item["name"].ToString();
file.Type = item["type"].ToString();
file.Url = item["link"].ToString();
file.ParentId = item["parent_id"].ToString();
file.Id = item["id"].ToString();
fileManager.Files.Add(file);
fileManager.FilesNames.Add(file.fName);
}
FileList.ItemsSource = fileManager.FilesNames;
}
else
{
infoTextBlock.Text = "Error calling API: " +
e.Error.ToString();
}
}
private void FileList_Tap(object sender, GestureEventArgs e)
{
foreach (File item in fileManager.Files)
{
if (item.fName == FileList.SelectedItem.ToString() )
{
switch (item.Type)
{
case "file":
MessageBox.Show("Still in progress");
break;
case "folder":
fileManager.CurrentFolderId = item.ParentId.ToString();
client.GetAsync(item.Id.ToString() + "/files");
break;
default:
MessageBox.Show("Coś nie działa");
break;
}
}
else if (FileList.SelectedItem.ToString() == "..")
{
client.GetAsync(fileManager.CurrentFolderId + "/files");
}
}
}
}
}
Running stop at that line.
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
You should check all of the URLs you have both in the XAML and code. When you get to the NavigationFailed function, it means that the phone tried to navigate to some page that did not existed. We would be able to help more if you could tell what were you doing when the app threw the exception.
System.Diagnostics.Debugger.Break();
usually happens because of an Uncaught Exception.
Either post the code which started giving problems, or the stack trace when you encounter this problem.
No one can tell anything without actually seeing what you are doing.