App refuses to connect to Parse backend - android

I am working on an app called TobaccoRoad that uses a library project called BestApproach. It uses a Parse backend to display custom generated content and handle push notifications. Everything was working pretty alright until a few days ago, when I must have messed up some settings somewhere and it no longer seems to be making the connection to the parse systems. I'm quite sure it's a local issue, because my second tester phone, which has not had updated code pushed to it in a few days, is still receiving notifications and can view that custom content.
The weird thing is, even after clearing my workspace and starting fresh from the (definitely good) code my employer gave me, and following all the tutorials and troubleshooting guides on Parse.com (see https://parse.com/docs/push_guide#installations/Android; https://parse.com/tutorials/android-push-notifications) I'm still not connecting to Parse. I haven't made any significant changes that I can recall, so I'm at a loss as to what might be causing this.
I know it's not an issue of a bad applicationID or clientKey, because even substituting random strings into the Parse.initialize call gave the same results, and a logcat error about not being able to authenticate.
Here are the relevant bits from my manifest files, first for the library project...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestapproach.lib"
android:versionCode="8"
android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name"
android:theme="#style/Theme.BA" >
<activity android:name="com.bestapproach.lib.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="#style/Theme.BA.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Declarations for all of my Activities...-->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
</manifest>
And the manifest is exactly the same for my dependent project, with the exception of where I define a custom receiver at the end:
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.bestapproach.lib.MyCustomReceiver">
<intent-filter>
<action android:name="com.bestapproach.lib.UPDATE_STATUS" />
</intent-filter>
</receiver>
And here's the code for the onCreate() method in my main activity (SplashActivity) where the Parse service is initialized:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
String parseClientId = getString(R.string.parse_client_id);
String parseAppId = getString(R.string.parse_app_id);
//debug output
Log.v("parse should be initializing...", parseAppId+" "+parseClientId);
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
PushService.subscribe(this, "", MenuActivity.class);
PushService.setDefaultPushCallback(this, SplashActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
final Activity a = this;
// Fetches content if it doesn't exist.
StoreManager sm = StoreManager.getInstance(a);
ParseStoreManager psm = ParseStoreManager.getInstance(a);
return;
}
}
Suggestions I've found that seem like they may be on track with what I need include running Parse.initialize() in the onCreate() of every activity, which I don't really want to do as there are a lot of them and that would be a lot of duplicated code, or generating an Application object and running it from there. Everything I've tried in relation to that has ended up breaking once I add it to my manifest file, due to TobaccoRoad's dependencies on the library project.
I know, it's a lot to dig through, but any suggestions would be appreciated. Thanks everybody.

Possible fix:
Change this line
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
to this:
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(SplashActivity.this, parseAppId, parseClientId);

the issue is that
ParseAnalytics.trackAppOpened(getIntent());
accepts the intent from that activity from your SplashActivity and from the application scope
Also, you initialize parse from the activity which we generally don't do.
We try initialize parse from the Application class so it has the context of the Application scope and not of the Activity Scope.
I recommend you to create an Application class and include the parse code in the onCreate of the Application...which you would need to do only once.
Or, you can create some BaseActivities and make all your activities in the application extend to that. This will save you from writing duplicate code...this is just in case you are bound not to create an Application class.
Pardon me for anything wrong...I am new in answering.

Related

My Android App is Overriding The Lyft App?

I built an Android app that is somehow taking over or overriding the Lyft driver app. Basically, whenever a user has my Android app downloaded, it somehow takes over her Lyft app. She will not get any ride requests from Lyft (even during the middle of a super busy time). Then, when she deletes my app, it works perfectly again. She immediately gets rides again. It is the weirdest thing I have ever seen. And this is not just coincidental, when she goes to kill her apps, it literally shows my app logo taking over the Lyft driver app. Notice how originally it has the Lyft logo. Then, when my app is installed, it has my logo for the Lyft app (my logo is just the default Android logo). She can even kill my app, and her Lyft and also Uber driver app do not work! The only way to fix it is to completely uninstall my app and restart her phone. Then, everything works perfectly. One important element is I do track the location all the time. I'm just not really sure where even to start with this bug, so any ideas are helpful. Thanks! The user is using a Galaxy Note 10+ with Android 10. None of our other Android users have told us about this problem. It seems to be a unique case for this phone.
Here are all my manifest and intents:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.danieljones.nomad_drivers">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<application
android:requestLegacyExternalStorage="true"
android:name=".parse.Parse"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".checkIn.CheckInActivity"
android:label="#string/title_activity_check_in"/>
<activity android:name=".insurance.analysis_activity.ZendriveAnalysisActivity" />
<activity android:name=".fare.breakdowns.FareBreakdownActivity" />
<activity
android:name=".navigation.HomeNavigationActivity"
android:label="#string/title_activity_home_navigation"
android:screenOrientation="portrait"/>
<activity android:name=".welcome.LoginActivity" />
<activity android:name=".welcome.special_code.CodeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".new_rides.ride_detail.NewRideDetailActivity" />
<activity android:name=".rides_lists.ride_detail.RideDetailActivity" />
<activity android:name=".personal_rides.ride_detail.PersonalRideDetailActivity" />
<activity android:name=".review_list.ReviewActivity"/>
<activity android:name=".user_profile.driver_card.EditProfileActivity" />
<activity android:name=".user_profile.edit_form.EditProfileFormActivity"/>
<receiver android:name=".insurance.zendrive.MyZendriveBroadcastReceiver" />
<activity android:name=".archived_rides.ride_detail.ArchivedRideDetailActivity" />
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService"
android:permission="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:name=".push_notifications.ParseCustomBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
I believe your issue is related to your defined name element in your Manifest.xml, specifically, the one underneath the application tag.
You have yours defined as: .parse.parse, which seems rather odd to me.
Looking at this link from the parse platform, I think that's what you are declaring as your app's name.
This name element, though it may seem unimportant, is actually where your application is generating the Application level Context from, or in this case, where the external Intents are being discovered.
It's highly likely that the system cannot distinguish which one to pull and it is therefore pulling yours over Lyft when it can.
To resolve this, just declare your own class that extends the Application class somewhere in your project like this:
public class MyApplication extends Application {
private static MyApplication sInstance;
#Override
public void onCreate() {
super.onCreate();
sInstance = this;
}
/**
* Get an instance of the application.
*
* #return {#link MyApplication}
*/
public static synchronized MyApplication getInstance() {
if (sInstance == null) {
sInstance = new MyApplication();
}
return sInstance;
}
/**
* Get context
*
* #return Context
*/
public static synchronized Context getContext() {
return getInstance().getApplicationContext();
}
}
Then just update your Manifest to look like this:
<application
.
android:name=".MyApplication"
.
.
.>
...
And it should function properly.
If you are still having troubles, update your question with more info and we can diagnose it further.

Android manifest for USBAccesory

I am making an app that communicates with a piece of usb hardware made by my company (this is the only app allowed to talk to the usb accessory, it's not a public api). I am having difficulties setting up the proper launch modes in the manifest.
There are three components to the app: the main activity, a login activity, and the USBService.
I'm assuming the intent for the main goes to the login activity, and the intent for the usb goes to the USBService, but I am not sure if I do this, will this start the service if the app is not running? More over, if it does, how do I fetch an already existing service?
What type of structure should I be looking at for the manifest file? (specifically, intent-filters, and appropriate launch modes... I've read a few documents about the launch modes but I am still not sure I quite understand... There should only ever be at most one instance of each activity/service, and they need to communicate together.
edit: it is not necessary for communications to start before the app is open, nor is it necessary to launch the app automatically when the usb is connected.
edit: my manifest as it stands, looks like:
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="mainpackage.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
<activity
android:name="mainpackage.LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<service android:name="updater.USBService"
android:exported="false" >
<!--
-->
</service>
</application>
in your manifest add
<manifest ...>
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk android:minSdkVersion="12" />
In this case, the following resource file should be saved in res/xml/device_filter.xml and specifies that any USB device with the specified attributes should be filtered:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1234" product-id="5678" class="255" subclass="66" protocol="1" />
</resources>
Hope this help.
Your manifest looks good,
I think you make a good choice for putting the intent-filter "android.hardware.usb.action.USB_ACCESSORY_ATTACHED" in the mainActivity and start the application in this activity,
and again I think it's a good choice to start your mainActivity in SingleTop launch mode,
because if an instance of the mainActivity already exists at the top of the current task, the system going to launch this activity, no new instance of this activity will be created.
For a best understanding of the different launch mode available in android,
I think this link may help you :
http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
To make a long story short I think you'll be all set with this manifest as is.
To Use Android Devices min SDK version should be set to 12 and need to declare following line in AndroidManifest.xml file
<>
<uses-sdk android:minSdkVersion="<version>" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
<activity ...>
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
</application>

ServiceTestCase is not launching my service

I am attempting to write some JUnit tests for my android application. The application is a service.
I have tried several things to get the ServiceTestCase to launch the service but it fails to.
HOWEVER, when i debug the ServiceTestCase it WILL launch the service. I belive this is because the ServiceTestCase is calling setup and not giving enough time for the service to launch before it kills it...
I am not completely sure, this is the first time i have ever used junit testing for android. VERY new to this. Any suggestions on what i can do to fix this problem?
I was thinking of creating some timer loop or something, but that seems REALLY dirty. Would like a much cleaner aproach.
Android Manifest for the service.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dataservice.server"
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<service android:name="dataservice.server.DataServer" android:process=":remote" android:exported="true" android:enabled="true">
<intent-filter>
<action android:name="dataservice.DataService.BIND.1" />
</intent-filter>
<intent-filter>
<action android:name= ".DataServer" />
</intent-filter>
</service>
<receiver android:name="dataservice.server.Receiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT"></action>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
</manifest>
The ServiceTestCase i am attempting.
public class Publish extends ServiceTestCase<DataServer> {
private final static String TAG = "Publish Unit Test";
private Context mSystemContext;
public Publish() {
super(DataServer.class);
}
public Publish(Class<DataServer> serviceClass) {
super(serviceClass);
}
#Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
// this is where i am attempting to start the service.
// i have attempted other methods, but none of those worked either.
startService(new Intent(this.getContext(), DataServer.class));
}
public void testPublish() {
}
}
I was referencing one of the dependant projects incorrectly. Once this was fixed, it resolved the issue. So, check and make sure you are referencing your projects correctly if you are having the same issue.

Unable to start Service Intent

I have a service class. I have exported this class to jar and I have embed the jar in my client app.
When needed, I call the service class. When I try to do this, I get the following error:
Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found
I have other class apart from the service class, which I am able to access (create object of that class) which are inside the same jar.
I feel I have missed out some thing in my configuration or manifest or so.
Please help me identifying the same. My code is below:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent () ;
intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;
this.startService(intent) ; // when I call this line I get the message...
// binding other process continue here
}
Client manifest.xml
<service android:name="com.sample.service.serviceClass"
android:exported="true" android:label="#string/app_name"
android:process=":remote">
<intent-filter><action android:name="com.sample.service.serviceClass"></action>
</intent-filter>
</service>
For anyone else coming across this thread I had this issue and was pulling my hair out.
I had the service declaration OUTSIDE of the '< application>' end tag DUH!
RIGHT:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
...
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity ...>
...
</activity>
<service android:name=".Service"/>
<receiver android:name=".Receiver">
<intent-filter>
...
</intent-filter>
</receiver>
</application>
<uses-permission android:name="..." />
WRONG but still compiles without errors:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
...
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity ...>
...
</activity>
</application>
<service android:name=".Service"/>
<receiver android:name=".Receiver">
<intent-filter>
...
</intent-filter>
</receiver>
<uses-permission android:name="..." />
First, you do not need android:process=":remote", so please remove it, since all it will do is take up extra RAM for no benefit.
Second, since the <service> element contains an action string, use it:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=new Intent("com.sample.service.serviceClass");
this.startService(intent);
}
1) check if service declaration in manifest is nested in application tag
<application>
<service android:name="" />
</application>
2) check if your service.java is in the same package or diff package as the activity
<application>
<!-- service.java exists in diff package -->
<service android:name="com.package.helper.service" />
</application>
<application>
<!-- service.java exists in same package -->
<service android:name=".service" />
</application>
I hope I can help someone with this info as well:
I moved my service class into another package and I fixed the references. The project was perfectly fine, BUT the service class could not be found by the activity.
By watching the log in logcat I noticed the warning about the issue: the activity could not find the service class, but the funny thing was that the package was incorrect, it contained a "/" char. The compiler was looking for
com.something./service.MyService
instead of
com.something.service.MyService
I moved the service class out from the package and back in and everything worked just fine.
In my case the 1 MB maximum cap for data transport by Intent.
I'll just use Cache or Storage.
I've found the same problem. I lost almost a day trying to start a service from OnClickListener method - outside the onCreate and after 1 day, I still failed!!!! Very frustrating!
I was looking at the sample example RemoteServiceController. Theirs works, but my implementation does not work!
The only way that was working for me, was from inside onCreate method. None of the other variants worked and believe me I've tried them all.
Conclusion:
If you put your service class in different package than the mainActivity, I'll get all kind of errors
Also the one "/" couldn't find path to the service, tried starting with Intent(package,className) and nothing , also other type of Intent starting
I moved the service class in the same package of the activity
Final form that works
Hopefully this helps someone by defining the listerners onClick inside the onCreate method like this:
public void onCreate() {
//some code......
Button btnStartSrv = (Button)findViewById(R.id.btnStartService);
Button btnStopSrv = (Button)findViewById(R.id.btnStopService);
btnStartSrv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startService(new Intent("RM_SRV_AIDL"));
}
});
btnStopSrv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
stopService(new Intent("RM_SRV_AIDL"));
}
});
} // end onCreate
Also very important for the Manifest file, be sure that service is child of application:
<application ... >
<activity ... >
...
</activity>
<service
android:name="com.mainActivity.MyRemoteGPSService"
android:label="GPSService"
android:process=":remote">
<intent-filter>
<action android:name="RM_SRV_AIDL" />
</intent-filter>
</service>
</application>

How to hide application icon from the Android Desktop?

I defined an application which is only used from my other application. So I would like to hide the icon of this application, so that the user can't see it on the desktop of his phone (or how do you call the thing where all apps are listed?). My manifest file looks the following way:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.games.pacman.controller"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".PacmanGame"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="pacman.intent.action.Launch" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="xyz.games.pacman.network.MessageListener">
<intent-filter>
<action android:name="xyz.games.pacman.controller.BROADCAST" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
I already read this question:
How to hide an application icon in Android emulator?
but if i just remove the line
<category android:name="android.intent.category.DEFAULT" />
in my manifest, the activity isn't working at all (ActivityNotFoundException in the calling activity).
Any hints how to solve this problem? I already tried android.intent.category.EMBEDDED but this doesn't work too.
In the Internet I found CommonsWare answer http://osdir.com/ml/Android-Developers/2010-06/msg03617.html that it can be done using PackageManager. Unfortunately, it isn't explained how exactly and I couldn't find a solution by browsing the PackageManager API.
You need to create a custom intent filter and then create an intent which uses that filter.
For example, in my Funky Expenses application external apps can add transactions. This is achieved by the manifest for Funky Expenses containing
<activity android:name="com.funkyandroid.banking.android.ExternalEntryActivity">
<intent-filter>
<action android:name="com.funkyandroid.action.NEW_TRANSACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and then external application can access my activity in the following way;
Intent launchIntent = new Intent();
launchIntent.setAction("com.funkyandroid.action.NEW_TRANSACTION");
... code to set parameters to be passed to activity ...
startActivity(launchIntent);
Pay special attention to the setAction call which sets the correct intent.
why would you write an actual (executable) second application that merely exists to do something when it receives sth from another app?
i'd suggest, you implement this "app" as a service (remote or local). this service would then run in the background and do stuff for you and there won't be any icons to be displayed on the screen for it...
if neccessary, you can implement this service to be remote, meaning it runs in a totally different process then the first app. and: you actually can communicate via broadcast intents as you seem to do by now so you won't need to change your first app...
Try removing the intent-filter and instead of trying to launch the 2nd activity with the filter lounch directly the activity:
Intent second = new Intent(context, xyz.games.pacman.controller.PacmanGame.class);
startActivity(second);
You must remove the whole <intent-filter>, not just the <category>

Categories

Resources