I'm trying to develop an app with GCM,
so I downloaded Sample project made by Google here
: https://developers.google.com/cloud-messaging/android/start
At the manifest of this project, there is code for GcmReceiver below:
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="gcm.play.android.samples.com.gcmquickstart" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
But At java package, there is no class named GcmReceiver below is the picture the sample project I have show me:
Just with the manifest xml file, is that GcmReceiver working well?
You have to add at least Play Services 7.5.0 to your project.
I suggest you to add latest library vs 8.3.0
Here's link for gradle users:
compile "com.google.android.gms:play-services:8.3.0"
Related
I have this code and I was told that for Android 11 I need to add the queries tag in manifest:
final PackageManager pm = getPackageManager();
Intent main = new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> packages = pm.queryIntentActivities(main, 0); //get a list of installed apps.
I was told it should be this:
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</queries>
Problem is I cannot add the <category> tag. Android Studio says that the element is not allowed there. I can only add the <action> and <data> tags inside <intent>. And it seems other people on SO have this problem too. It's strange because Android's own documentation instructs us to use the <category> tag there.
The <queries> section is introduced in API 30, so be sure you use it only if you target such version upward.
It is indeed needed when, for instance, you want to launch some other apps from yours, knowing only their package name. Otherwise, using the package manager will return you some null when using functions like packageManager.getLaunchIntentForPackage("com.yyy"). You can find more information here: Package visibility in Android 11
In your case, you can just write the section like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx">
...
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</queries>
...
</manifest>
I am developing a Android Studio project using gradle 2.2 and Google Play Services 12.0.1. I am now trying to add functionality from Google Play Services.
The thing is I am unable to import the Google Play Service library. When I try the following line.
import com.google.android.gms.games.Games;
Or anything similar i get "Cannot resolve symbol Games", Android Studio proposes "Add library <...> to classpath" but that does not seem to change anything.
What I have done so far
I started out following this setup guide. Which simply says to update your build.gradle. My top-level build.gradle contains this,
project(":android") {
apply plugin: "android"
apply plugin: 'com.android.application'
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
< ... >
compile "com.google.android.gms:play-services-games:12.0.1"
}
}
I have also ensured that the buildscript section contains the maven link. I have also checked that Google Play Services are installed from the "SDK Tools" pane in the SDK manager. In addition to this I have added the correct version of Play Services as a dependency in Project structure -> Modules -> Dependencies. Someone suggested on earlier Stack Overflow questions that adding
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
to the AndroidManifest might help, so my Manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wizard_team.wizards_tale" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="wizard_team.wizards_tale.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
I do not receive any error messages when I resync and I have tried to update and restart Android Studio several times. I have also tried "Invalidate chaches/restart..".
During my quest on Google I have found several people experiencing the same problem and I have tried their solutions but nothing has worked. I have spent way to long with this problem, does anyone have any suggestions?
Solved it. As I do not have much experience creating apps I tried importing google play services into the core-module part of my app. For anyone else just getting started, the android specific code such as this should go in android -> java -> [package-name].
Might seem trivial, but as a beginner using this setup tool this problem kept me searching for hours.
Before labeling this as a duplicate:
I've read at least 15 similar threads and each and every one is either using the old Parse code (the now deprecated setDefaultPushCallback) or the problem was a result of calling Parse.initialize(...) in an activity and not in the Application class. But this is not applicable to my case. The official example (which I'm using) is evidently doing it right, so the code is already in the Application class.
I've downloaded the Push Starter example from Parse's official guides and tried it out on an emulator. I receive pushes only while the app is running. The moment's it's closed (removed from the "recent apps" list, not force killed), I no longer get pushes. Which makes the entire feature rather useless... I tried with and without GCM, the behavior is the same.
Any clues what could possible be wrong? All classes are the stock example ones, nothing overridden or added by me (except for the id/key and the ParsePush.subscribeInBackground call which I copied from the guide). Weirdly enough, the example code did not contain ParsePush.subscribeInBackground and the QuickStart does not mention it. It even gives a Test button that supposedly sends a push which I never receive, with or without subscribeInBackground. The only way I've been able to get a push so far was with subscribeInBackground and sending a push manually though the web console, and only so if the app is running. The web console also keeps telling there's 2 registered devices... which is untrue.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
<application
android:name=".ParseApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:allowBackup="true">
<activity
android:name=".ParseStarterProjectActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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.parse.ParsePushBroadcastReceiver"
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>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
</application>
</manifest>
ParseApplication:
package com.parse.starter;
...
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize Crash Reporting.
ParseCrashReporting.enable(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
ParseUser.enableAutomaticUser();
// Add your initialization code here
Parse.initialize(this, "***", "***");
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
}
Just to clarify why you are seeing this behaviour, Parse has two different ways for delivering push notifications:
"Parse way": the Parse SDK has a component running in your app, which keeps a connection to the Parse backend servers. This will only work when your app is actually running, because killing it breaks the connection with the Parse backend.
GCM "Google" push notifications: This works via Google Play Services, an app which is always running in the background and that can start your app when needed. This will always work, unless you force stop the application.
In your case you are there is a package name conflict: com.parse.starter is the package name that was actually included in the example. This causes GCM not to work, because it already knows the package under a different signature. Changing your package name to something unique like com.parse.kaqqao should solve the trick.
There are a few reasons for this:
There are two BroadcastReceiver viz the "com.parse.ParsePushBroadcastReceiver" and "com.parse.GcmBroadcastReceiver". I believe that the first receiver is getting prioritized over the GCMBroadcastReceiver and thus the behavior is not affected by removing or keeping this receiver. It could also be due to action "com.parse.push.intent.RECEIVE", which might be handling the push messages RECEIVE action. If both the receiver perform the same task of parsing the Push message (starting the same service in background), then include the intent-filter inside one receiver and let it handle all kinds of push messages. Since GCMBroadcastReceiver holds the C2DM permission.
Try changing the order of the two broadcast receiver tags in the manifest. (Keep GCMBroadcastReceiver before the ParsePushBroadcastReceiver)
It could be due to android:exported="false", maybe it prevents the Receiver from listening to the push messages sent by server. Try changing to true.
Yesterday everything worked fine with my project, but today I receive very weird errors :
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.redonbas/com.example.redonbas.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.redonbas.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.redonbas-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.redonbas-2, /vendor/lib, /system/lib]]
My AndroidManifest :
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
MainActivity is in correct package:
I refered to the problem but I copied all the File System of the project to the new, but that didn't help. I also created new project with another package and manually copied all the stuff from the old project there - the problem still remains!
What's wrong with it?
Uncheck your Android Dependencies and Android Private Libraries Checkboxes.
Yes, the problem was in past SherlockActionBar and its android-support library implementing .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android">
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:name=".hba1c" android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I'm trying to learn Java and need some help with AndroidManifest.xml
My little hello world project is working code-wise, but I'm confused with making changes to the manifest. Specifically, in the code above package name is "com.android" and in data/app my app shows up as com.android-1.apk. When I try to change it to something like com.jocala or com.jocala.hba1c I get package R does not exist errors through my compile, which fails.
What changes do I need to make? Anything else here that is glaringly bad?
I am working using Ant, VI and the Linux console, no Eclipse.
You should change the package of the java code, let it in accordance with the package which you defined in the manifest file.
The manifest holds meta-data corresponding to your android application. Hence, if you needs changes in the package name, make the changes in the java files, change the package name there, there is no sense making a change here. The only changes that are majorly done in the manifest are activity related(for beginners). Have a read here.