I am using AndroidIbeacon library released by radiusnetworks and I am able to run their demo app successfully. But when I add that to my application onIBeaconServiceConnect() method is not called.
Below my code,
public class Sample extends Activity implements IBeaconConsumer {
protected static final String TAG = "Sample";
private IBeaconManager iBeaconManager = IBeaconManager
.getInstanceForApplication(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
iBeaconManager.bind(this);
}
#Override
protected void onDestroy() {
super.onDestroy();
iBeaconManager.unBind(this);
}
#Override
public void onIBeaconServiceConnect() {
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
#Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an iBeacon for the firt time!");
}
#Override
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an iBeacon");
}
#Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG,
"I have just switched from seeing/not seeing iBeacons: "
+ state);
}
});
try {
iBeaconManager.startMonitoringBeaconsInRegion(new Region(
"myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) {
}
}
}
Kindly help me to solve this issue. thanks
If manifest merging does not work, try this (worked for me):
Add the following service declarations to your AnroidManifest.xml, replacing {my app's package name} with the fully qualified package name of your Android application.
<service android:enabled="true"
android:exported="true"
android:isolatedProcess="false"
android:label="iBeacon"
android:name="com.radiusnetworks.ibeacon.service.IBeaconService">
</service>
<service android:enabled="true"
android:name="com.radiusnetworks.ibeacon.IBeaconIntentProcessor">
<meta-data android:name="background" android:value="true" />
<intent-filter
android:priority="1" >
<action android:name="{my app's package name}.DID_RANGING" />
<action android:name="{my app's package name}.DID_MONITORING" />
</intent-filter>
</service>
The most common cause of this issue is that the proper entries to start the library's service are not in the project AndroudManifest.xml file. Your new project must pull in these entries from the library's manifest using a feature called manifest merging.
Make sure you have followed the setup instructions here. If using Eclipse, verify your project.properties has manifestmerger.enabled=true.
adding
manifestmerger.enabled=true
in project.properties worked for me!
Source
Related
I've implemented iOS and Android SDK, now I'm testing my app configuration in test environment. While with iOS everything seems working fine, I've noticed that with Android, the install event is correctly attributed to my quick link, any other events I'm sending (even thos I can correctly see them in the liveview) are not attributed to the quick link used to open the app.
Here my dependencies:
com.android.tools.build:gradle:3.1.1
com.google.gms:google-services:4.2.0
io.fabric.tools:gradle:1.31.0
com.android.support:appcompat-v7:28.0.0
Here the main lines of code:
#Override
protected void handleOnStart() {
super.handleOnStart();
Branch.enableDebugMode();
// Branch object initialization
Branch.getAutoInstance(this.getActivity().getApplication());
branchInstance = Branch.getInstance();
branchInstance.disableTracking(trackingDisabled);
branchInstance.initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error != null) {
log("onInitFinished - " + error.getMessage());
} else {
log("onInitFinished invoked with " + referringParams.toString());
testEvent();
// Retrieve deeplink keys from 'referringParams' and evaluate the values to determine where to route the user
// Check '+clicked_branch_link' before deciding whether to use your Branch routing logic
}
}
}, getActivity().getIntent().getData(), getActivity());
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
private void testEvent() {
BranchEvent event = new BranchEvent(BRANCH_STANDARD_EVENT.VIEW_ITEM);
event.logEvent(this.getActivity());
}
And my AndroidManifest.xml looks like this:
<application android:launchMode="singleTask" .....>
<meta-data android:name="io.branch.sdk.BranchKey" android:value="#string/branchio_key_live" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="#string/branchio_key_test" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="#bool/branchio_test_mode" />
<receiver android:enabled="#bool/branchio_track_referral_active" android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
It looks like your code is slightly different than what we recommend in our Android Docs, so I would recommend you conform your code as closely as possible to our code snippets as possible. For example, we recommend initializing in the onStart() method whereas you are doing yours in handleOnStart(). Here are the Android docs: https://docs.branch.io/apps/android/
If you do this and are still having difficulties, please send an email to support#branch.io and provide your App ID which is found in your Account Settings on your dashboard so we can investigate this further.
I'm trying to integrate InMobi in my app and I can show banner ads successfully but unable to add interstitial ads.
I've added this code in the activity from where I want to show ad.
InMobi.setLogLevel(InMobi.LOG_LEVEL.DEBUG);
InMobi.initialize(this, "Property-id");
final IMInterstitial interstitial = new IMInterstitial(this, "Property-id");
interstitial.setIMInterstitialListener(new IMInterstitialListener() {
#Override
public void onInterstitialFailed(IMInterstitial imInterstitial, IMErrorCode imErrorCode) {
Log.e(DEBUG_TAG, "Interstitial failed" + "... Error code = " + imErrorCode +
"... Internstial = " + imInterstitial);
}
#Override
public void onInterstitialLoaded(IMInterstitial imInterstitial) {
Log.e(DEBUG_TAG, "interstitial loaded");
if (interstitial.getState() == IMInterstitial.State.READY) {
interstitial.show();
}
}
#Override
public void onShowInterstitialScreen(IMInterstitial imInterstitial) {
}
#Override
public void onDismissInterstitialScreen(IMInterstitial imInterstitial) {
}
#Override
public void onInterstitialInteraction(IMInterstitial imInterstitial, Map<String, String> stringStringMap) {
}
#Override
public void onLeaveApplication(IMInterstitial imInterstitial) {
}
});
interstitial.loadInterstitial();
And for testing, I've added everything mentioned here in AndroidManifest.xml file. I've added all the permissions there, hardwareAccelerated=true in application tag and this:
<activity
android:name="com.inmobi.androidsdk.IMBrowserActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:hardwareAccelerated="true"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<receiver
android:name="com.inmobi.commons.analytics.androidsdk.IMAdTrackerReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.inmobi.share.id" />
</intent-filter>
</receiver>
<service
android:name="com.inmobi.commons.internal.ActivityRecognitionManager"
android:enabled="true" />
But I keep getting this error "The ad request was successful, but no ad was returned" and after a small time gap, it gives "Ad network failed to retrieve ad".
For banner ads it worked successfully though. I tried it again but it's not working now. Is there something wrong with inmobi diagnostics as mentioned here (Sohan says this in his comments).
I'm from the InMobi team. Are you replacing the "Property-Id" in your code with your actual property id? I'm unsure if the code you provided above is your actual code or for illustrative purposes only...
I´m using the Android IBeacon Library for a Project. I need to create a Service that starts ranging for beacons in the background and notify the user when it finds one (the nearest one). I have searched a lot and coded based on many examples I have found, but still it doesn´t work. Using logs I found that the IBeaconManager doesn't bind, so onIBeaconServiceConnect never gets called. I have already tried some solutions I found here but none of them has been useful. I would really appreciate if someone could help me solving this problem. I post some of my code here
public class RangingService extends Service implements IBeaconConsumer
{
private IBeaconManager beaconManager;
#Override
public void onCreate()
{
super.onCreate();
beaconManager = IBeaconManager.getInstanceForApplication(this);
Log.d("RangingService","Created beaconManager instance");
beaconManager.setBackgroundBetweenScanPeriod(120000);
beaconManager.setBackgroundScanPeriod(30000);
beaconManager.bind(this);
if(beaconManager.isBound(this))
{
Log.d("RangingService","Beacon manager bound");
}
else
{
Log.d("RangingService","Beacon manager not bound");
}
//Show the service has started
notify("RangingService created", "RangingService has started");
}
#Override
public void onDestroy()
{
super.onDestroy();
beaconManager.unBind(this);
}
#Override
public void onIBeaconServiceConnect()
{
Log.d("RangingService", "Entering onIBeaconServiceConnect");
beaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<IBeacon> beacons, Region region)
{
if(beacons.size() > 0)
{
IBeacon nearestBeacon = beacons.iterator().next();
for(IBeacon b : beacons)
{
if(nearestBeacon.getProximity() == IBeacon.PROXIMITY_UNKNOWN)
{
nearestBeacon = b;
}
else
{
if(b.getProximity() != IBeacon.PROXIMITY_UNKNOWN)
{
if(b.getAccuracy() < nearestBeacon.getAccuracy())
{
nearestBeacon = b;
}
}
}
}
Log.d("RangingService","Nearest Beacon Found "+nearestBeacon.getMajor()+";"+nearestBeacon.getMinor());
notify("Beacon read","Major: "+nearestBeacon.getMajor()+"; Minor: "+nearestBeacon.getMinor());
}
else
{
Log.d("RangingService","No beacons");
}
}
});
try
{
Log.d("RangingService", "Entering startRangingBeacons");
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
}
catch(RemoteException e)
{
notificar("Error", e.getMessage());
Log.e("RangingService", "Error while starting scanning: "+e.getMessage());
}
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Log.d("RangingService", "Entering onBind");
return null;
}
The Service is already in my manifest also. Thanks for your help.
A couple of points:
The code indicates you are using a 0.x version of the Android iBeacon Library. If you are starting a new project, I would strongly recommend you use the Android Beacon Library 2.0, as the earlier library is no longer actively maintained, and it is now hard to find documentation for it.
Regardless of the library version you are using, you should be able to get a callback to the onBeaconServiceConnect() method after you bind to the BeaconManager. The fact that you don't get this callback probably indicates that the BeaconService is not starting up properly.
The most likely reason that the BeaconService is not starting up properly is because it is not properly declared in the manifest. If you are using Eclipse, you must edit your project.properties file and add the line: manifestmerger.enabled=true. If you are using AndroidStudio, this is not necessary. If you are using IntelliJ, you may have to declare the service manually.
You can verify if the manifest has the proper entries by looking at the generated manifest file in bin/AndroidManifest.xml, and verifying it has an entry for the BeaconService.
I had faced similar issues. Got resolved by doing following things
In eclipse project.properties added manifestmerger.enabled=true
restarted the eclipse
uninstalled other beacon apps in my android phone and restarted the phone
I've got a problem. My AdMob has been set up for some time now without any problem, but I noticed something wrong. Ad gets successfully loaded (i see message from ddms), but it won't show. It will get shown after periodical 60 seconds refresh or when I open up login to google plus. The problem happens only with Google Play Services AdMob and not with AdMobSDK jar. I'd switch to AdMob jar, however I'm using Google Play Game Services for leaderboards and achievements.
I suspect the problem is with view not being shown, or inproper settings.
So again, ad will show itself after 60 seconds (along with ad refresh) of waiting, or when I fire up the log in screen for google play services.
I'm adding my code, also I should mention that I've switched to new AdMob website and I repeat, that problem is not happening if I use AdMob jar file (the ad is then shown in 2-3 seconds like normal). I've cut the google play game services code (they don't affect this issue because i've tried in my other app without them, and the problem is still there).
MainActivity code:
public class MainActivity extends AndroidApplication {
public static enum AdsStatus {
SHOW_ADS, HIDE_ADS;
}
protected RelativeLayout layout;
protected static AdView adMobView;
public static class InnerHandler extends Handler {
WeakReference<MainActivity> mActivity;
InnerHandler(MainActivityactivity) {
mActivity = new WeakReference<MainActivity>(activity);
}
#Override
public void handleMessage(final Message msg) {
if(msg.obj instanceof AdsStatus) {
switch((AdsStatus)msg.obj) {
case SHOW_ADS:
mActivity.get().showAds();
break;
case HIDE_ADS:
mActivity.get().hideAds();
break;
}
}
}
}
protected Handler handler = new InnerHandler(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MainApplicationListener(), true);
layout.addView(gameView);
//Ad Mob
final DisplayMetrics displayMetrics = MainActivity.this
.getApplicationContext().getResources()
.getDisplayMetrics();
if (displayMetrics.widthPixels >= 800 && displayMetrics.heightPixels >= 480) {
if(adMobView != null) {
adMobView.destroy();
}
adMobView = new AdView(AirDance.this);
adMobView.setAdUnitId(<MY_ID_IS_HERE>);
adMobView.setAdSize(AdSize.SMART_BANNER);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(<MY_DEVICE_IS_HERE>)
.build();
adMobView.loadAd(adRequest);
layout.addView(adMobView, adParams);
}
// Hook it all up
setContentView(layout);
}
#Override
protected void onResume() {
super.onResume();
AppRater.applicationLaunched(this, analytics);
if(adMobView != null) {
adMobView.resume();
}
}
#Override
protected void onPause() {
super.onPause();
if(adMobView != null) {
adMobView.pause();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
if(adMobView != null) {
adMobView.destroy();
adMobView = null;
}
}
public void showAds() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if(adMobView != null) {
adMobView.setEnabled(true);
adMobView.setVisibility(View.VISIBLE);
}
}
});
}
public void hideAds() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if(adMobView != null) {
adMobView.setEnabled(false);
adMobView.setVisibility(View.GONE);
}
}
});
}
}
And here is AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
android:installLocation="auto"
android:versionCode="16"
android:versionName="1.2.6" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<uses-feature android:name="android.hardware.touchscreen.multitouch" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="MainActivity">
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="...MainActivity"
android:label="MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- adMob -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
EDIT :
okay, so ad gets visible after I lock and unlock screen with app open, also you can click on invisible ad
EDIT :
Okay I think I solved it. I just manually reload whole layout onAdLoad event. Anyway, this is just functional solution, it does not explain why it happens with Google Play
Services AdMob.
adMobView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
layout.requestLayout();
}
});
}
});
As nobody has replied with explanation, I'm going to consider this one solved. I just manually reload whole layout onAdLoad event. Anyway, this is just functional solution, it does not explain why it happens with Google Play Services AdMob.
adMobView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
layout.requestLayout();
}
});
}
});
Also, as mentioned by user3263204, you can try this
adMobView.setBackgroundColor(Color.BLACK);
to solve your problem.
The above solution works. Even a simpler way to keep the banner shown is to set its background.
adMobView.setBackgroundColor(Color.BLACK);
As user3263204 says, you can use setBackgroundColor to make the adview appear.
You can make the background transparent, if (as in my case) you have the adview over something else:
adMobView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
You can also requestWindowFeature(Window.FEATURE_NO_TITLE); and set to full screen and the ads shows.
banner.setBackgroundColor(Color.TRANSPARENT);
This seems to fix the issue for me. Also be sure to run the banner creation code from within the UI thread.
activity.runOnUiThread(new Runnable()
{
#Override
public void run()
{
// all your banner creation code is here
banner.setBackgroundColor(Color.TRANSPARENT);
}
});
With Glass you can launch an app via the 'OK, Glass' menu and it seems to pick the nearest match unless a command is miles off, and you can obviously see the list of commands.
Is there anyway from within the app, or from the voice prompt (after the initial app trigger) to have a similar list given and return the nearest match.
Random (non-real world) example, an app that shows you a colour, "OK Glass, show the colour red"
'show the colour' could be your voice trigger and seems to be matched by glass on a 'nearest neighbor' method, however 'red' is just read in as free text and could be easily misheard as 'dread' or 'head', or even 'read' as there is no way of differentiating 'read' from 'red'.
Is there a way to pass a list of pre-approved option (red, green, blue, orange*, etc.) to this stage, or to another voice prompt within the app so the user can see the list and get more accurate results when there is a finite set of expected responses (like the main ok glass screen)?
*ok well nothing rhymes with orange, we're probably safe there
The Google GDK doesn't support this feature yet. However, the necessary features are already available in some libraries and you can use them as long as the GDK doesn't support this natively.
What you have to do:
Pull the GlassVoice.apk from your Glass: adb pull /system/app/GlassVoice.apk
Use dex2jar to convert this apk into a jar file.
Add the jar file to your build path
Now you can use this library like this:
public class VoiceActivity extends Activity {
private VoiceInputHelper mVoiceInputHelper;
private VoiceConfig mVoiceConfig;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.voice_activity);
String[] items = {"red", "green", "blue", "orange"};
mVoiceConfig = new VoiceConfig("MyVoiceConfig", items);
mVoiceInputHelper = new VoiceInputHelper(this, new MyVoiceListener(mVoiceConfig),
VoiceInputHelper.newUserActivityObserver(this));
}
#Override
protected void onResume() {
super.onResume();
mVoiceInputHelper.addVoiceServiceListener();
}
#Override
protected void onPause() {
super.onPause();
mVoiceInputHelper.removeVoiceServiceListener();
}
public class MyVoiceListener implements VoiceListener {
protected final VoiceConfig voiceConfig;
public MyVoiceListener(VoiceConfig voiceConfig) {
this.voiceConfig = voiceConfig;
}
#Override
public void onVoiceServiceConnected() {
mVoiceInputHelper.setVoiceConfig(mVoiceConfig, false);
}
#Override
public void onVoiceServiceDisconnected() {
}
#Override
public VoiceConfig onVoiceCommand(VoiceCommand vc) {
String recognizedStr = vc.getLiteral();
Log.i("VoiceActivity", "Recognized text: "+recognizedStr);
return voiceConfig;
}
#Override
public FormattingLogger getLogger() {
return FormattingLoggers.getContextLogger();
}
#Override
public boolean isRunning() {
return true;
}
#Override
public boolean onResampledAudioData(byte[] arg0, int arg1, int arg2) {
return false;
}
#Override
public boolean onVoiceAmplitudeChanged(double arg0) {
return false;
}
#Override
public void onVoiceConfigChanged(VoiceConfig arg0, boolean arg1) {
}
}
}
You can take advantage of the disambiguation step that occurs when multiple Activities or Services support the same Voice Trigger: simply have multiple Activities or Services in your application support "show me the color" as the voice trigger and label them with the color options.
Your manifest would look something like:
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/icon_50"
>
<activity
android:name="com.mycompany.RedActivity"
android:label="#string/red"
android:icon="#drawable/icon_red"
>
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER"/>
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/activity_start"
/>
</activity>
<activity
android:name="com.mycompany.BlueActivity"
android:label="#string/blue"
android:icon="#drawable/icon_blue"
>
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER"/>
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/activity_start"
/>
</activity>
<!-- ... -->
</application>
Those Activities or Services would only be used as a "trampoline" to launch the main logic of your app with the color selection.
If you haven't already, you should take a look at contextual voice menus that were added just a few weeks ago to the GDK. I had your exact same problem just the day before it was released, looking at it the next day and finding this helped me a lot! :)