Notifications are not working anymore. How to fix it? - java

My application implements 5 type of Custom Notifications.
In february, everething worked fine.
I'm now working back on it and there are no Notification displayed anymore.
First, i made a test With firebase cloud messaging. A notificication is successfully shown on my devices.
Then, i tried to modify my code folowing this answer:
Notification not showing in Oreo.
Without success.
Here is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.philipp.us">
<uses-permission
android:name="android.permission.GET_ACCOUNTS"
android:maxSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<!-- for android -->
<!-- <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/> -->
<!-- <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS"/> -->
<!-- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> -->
<!-- <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> -->
<!-- for Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
<!-- for htc -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT" />
<!-- for sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />
<uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE" />
<!-- for apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT" />
<!-- for solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE" />
<!-- for huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
<!-- for ZUK -->
<uses-permission android:name="android.permission.READ_APP_BADGE" />
<!-- for OPPO -->
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" />
<!-- for EvMe -->
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ" />
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.INTERACT_ACROSS_USERS_FULL"
android:protectionLevel="signature"
tools:ignore="ProtectedPermissions" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.philipp.android.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Translucent"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.philipp.android.ConversationActivity"
android:label="#string/menu_item_conversations"
android:windowSoftInputMode="stateHidden|adjustResize" />
<service android:name="com.example.philipp.android.PushMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.example.philipp.android.PushIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!--
Set custom default icon. This is used when no icon is set for incoming notification messages.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<activity
android:name="com.example.philipp.android.UserProfileActivity"
android:label="#string/menu_item_userprofile"
android:windowSoftInputMode="stateHidden|adjustPan" />
<provider
android:name="com.example.philipp.android.GenericFileProvider"
android:authorities="${applicationId}.my.package.name.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
<receiver
android:name="com.example.philipp.android.PushMessagingService$NotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="NOTIFICATION_RECEIVE" />
</intent-filter>
</receiver>
<activity
android:name="com.example.philipp.android.SubscriptionActivity"
android:label="#string/title_activity_subscription"
android:theme="#style/AppTheme.NoActionBar"/>
</application>
</manifest>
and this is my first Custom Notifications:
DataBaseHelper2 dbHelper2;
File storageDir;
Context context;
FirebaseStorage storage = FirebaseStorage.getInstance();
public PushMessagingService() {
context = this;
}
public static class NotificationID {
private static final AtomicInteger c = new AtomicInteger(5);
public static int getID() {
return c.incrementAndGet();
}
}
public static int notifbadgeCount = 0;
final String TAG = "PushMessageReceiver";
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
notifbadgeCount++;
ShortcutBadger.applyCount(context, notifbadgeCount); //for 1.1.4+
dbHelper2 = new DataBaseHelper2();
storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Log.d(TAG, remoteMessage.toString());
final Map<String, String> data = remoteMessage.getData();
Log.d(TAG, data.get("message") + " " + data.get("sender") + " " + data.get("sender_id") + " " + data.get("type") + " " + data.get("id") + " " + data.get("photo"));
int icon = R.drawable._logo_us_without_bkgrdxxxhdpi;
long when = System.currentTimeMillis();
if (isRunning(this) && data.get("type").equals("greeting")) {
Log.d(TAG, "GREETING");
}
//KEYWORD MATCH
if (data.get("type").equals("question")) {
Log.d(TAG, "QUESTION");
// Get the layouts to use in the custom notification
//NORMALSIZE
//Set Notification remote Layout
RemoteViews notificationLayoutkeywordmatch = new RemoteViews(getPackageName(), R.layout.notification_keywordmatch);
//User Photo
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_userprofilpic, R.drawable._btn_addprofilpicmdpi);
//Header
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_applogo, R.drawable._logo_us_without_bkgrdmdpi);
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_app_name, "ask Us");
notificationLayoutkeywordmatch.setTextViewText(R.id.lbl_date_and_time, DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME));
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_notification_type, R.drawable._ic_questionxxxhdpi);
notificationLayoutkeywordmatch.setImageViewResource(R.id.notification_arrow_down, R.drawable.simple_arrow_downmdpi);
//Body
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_text, getString(R.string.notif_keyword_match));
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_sender, data.get("sender"));
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_question, data.get("message"));
//EXSTENDED SIZE
//Set Notification remote Layout
RemoteViews notificationLayoutkeywordmatchexpanded = new RemoteViews(getPackageName(), R.layout.notification_keywordmatchexpanded);
//User Photo
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_userprofilpic, R.drawable._btn_addprofilpicmdpi);
//Header
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_applogo, R.drawable._logo_us_without_bkgrdmdpi);
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_app_name, "ask Us");
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.lbl_date_and_time, DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME));
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.notification_arrow_up, R.drawable.simple_arrow_upmdpi);
//Body
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_text, getString(R.string.notif_keyword_match));
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_notification_type, R.drawable._ic_questionxxxhdpi);
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_sender, data.get("sender")+ ":");
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_question, data.get("message"));
//Set Notification Channel
final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 1;
String channelId = "channel-01";
String channelName = "Someone could need you";
int importance = NotificationManager.IMPORTANCE_HIGH;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
mNotificationManager.createNotificationChannel(mChannel);
}
//Set Pending Intent
final Intent ii = new Intent(context.getApplicationContext(), ConversationActivity.class);
ii.putExtra("questionId", data.get("id"));
ii.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, ii, PendingIntent.FLAG_UPDATE_CURRENT);
// Apply the layouts to the notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable._logo_us_without_bkgrdmdpi)
.setCustomContentView(notificationLayoutkeywordmatch)
.setCustomBigContentView(notificationLayoutkeywordmatchexpanded)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setChannelId(channelId);
// Build notification
final Notification notification = mBuilder.build();
final NotificationTarget notificationTarget = new NotificationTarget(context, R.id.img_userprofilpic, notificationLayoutkeywordmatch, notification, 0);
final NotificationTarget notificationTargetExpanded = new NotificationTarget(context, R.id.img_userprofilpic, notificationLayoutkeywordmatchexpanded, notification, 0);
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
Glide.with(getApplicationContext())
.asBitmap()
.load(data.get("photo"))
.into(notificationTarget);
Glide.with(getApplicationContext())
.asBitmap()
.load(data.get("photo"))
.into(notificationTargetExpanded);
}
});
mNotificationManager.notify(notificationId, notification);
}```
Thank you for help.

android above oreo will not show the notification in the foreground. You need to show it in the alert dialog

Related

Clicking on push notification in android generated by AWS SDK for Unity not opening app

I am using AWS SNS SDK for Unity to receive push notifications in android and ios devices. I was able to get the notifications working in both but in android devices clicking on the notification does not open the app.
The codebase is more than 2 years old. Also, I am not familiar with java.
Based on my understanding the Utils.java file contains the implementation for notification's tap action. They have hardcorded the title to empty string so I don't get title in the notification. But I am not sure about the reason for application not opening when the notification is clicked.
Utils.java
package com.amazonaws.unity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.v4.app.NotificationCompat;
import com.unity3d.player.UnityPlayerProxyActivity;
public class Utils {
private static final int REQUEST_CODE = 1001;
private static final int NOTIFICATION_ID = 1;
public static void showNotification(Context context, String contentTitle,
String contentText) {
// Intent
Intent intent = new Intent(context, UnityPlayerProxyActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context.getApplicationContext());
builder.setContentIntent(contentIntent);
builder.setContentText(contentText);
builder.setContentTitle(contentTitle);
builder.setWhen(System.currentTimeMillis());
builder.setAutoCancel(true);
Resources res = context.getResources();
builder.setSmallIcon(res.getIdentifier("app_icon", "drawable",
context.getPackageName()));
builder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFICATION_ID, builder.build());
}
public static void showNotification(Context context, String contentText) {
showNotification(context, "", contentText);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.unity"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE" />
<application
android:theme="#android:style/Theme.NoTitleBar"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
<receiver
android:name="com.amazonaws.unity.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"/>
<category android:name="com.amazonaws.unity" />
</intent-filter>
</receiver>
<service android:name="com.amazonaws.unity.GCMIntentService" />
</application>
</manifest>

BroadcastReceiver can't detect/read sms

I'm building an app that would read incoming SMS. But, my BroadcastReceiver class can't detect/read incoming SMS. I think my code is correct but still it's not working.
Here's my code:
[XML]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.crashlocator.carlax.crashlocator">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<activity android:name=".MainActivity2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<receiver
android:name=".SmsReceiver"
android:exported="true" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
[JAVA CLASS]
public class SmsReceiver extends BroadcastReceiver {
private static final String SMS_BUNDLE = "pdus";
private String smsBody, address;
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Test",Toast.LENGTH_LONG);
}
public void showNotification(Context context) {
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, MapsActivity.class), 0);
v.vibrate(500);
Intent in = new Intent("SmsMessage.intent.MAIN").
putExtra("get_msg", address + ":" + smsBody);
context.sendBroadcast(in);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
//.setSmallIcon(R.drawable.notif1)
.setContentTitle("Attention!")
.setContentText("Car crash occure.");
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
I think you forgot to put .show() at the end of Toast.
Toast.makeText(context, "Test" ,Toast.LENGTH_LONG).show();

Incoming SMS contents

I wish I could get the contents of an incoming sms but its not working ..
In fact, no toast will appear, and nothing appears in the log, I think the myreceiver is not initialized ...
So here is the manifest, the onCreate the first activity, and my receiver java file : Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.locateit.antholife.locateit">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<receiver android:name=".MyReceiver">
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<application
android:allowBackup="true"
android:icon="#mipmap/locate"
android:label="#string/app_nameprincipal"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Changelog"
android:label="#string/title_activity_changelog"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBfmF3WWxsPhufZR5keiDNRy-33hJI1rvM" />
<activity
android:name=".lequipe"
android:label="#string/nomequipe" />
<activity
android:name=".Setting"
android:label="#string/title_activity_setting" />
<activity android:name=".MDPinterne" />
<activity android:name=".Bluetooth"></activity>
</application>
</manifest>
onCreate :
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
MyReceiver sms = new MyReceiver();
Log.v("aha3", "smslancer");
and java file :
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
Bundle extra = intent.getExtras();
if (extra != null) {
Object[] pdus = (Object[]) extra.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
if (messages.length > -1) {
Log.v("Ch", "Marche1");
for (int i = 0; i < messages.length; i++) {
Log.v("Ch", "Marche2");
final String messageBody = messages[i].getMessageBody();
final String phoneNumber = messages[i].getDisplayOriginatingAddress();
Toast.makeText(context, "Expéditeur:" + phoneNumber, Toast.LENGTH_LONG).show();
Toast.makeText(context, "Message : " + messageBody, Toast.LENGTH_LONG).show();
}
}
}
}
}
Move your receiver XML in your manifest to within the application tags.
<application
android:allowBackup="true"
android:icon="#mipmap/locate"
android:label="#string/app_nameprincipal"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
.......
<receiver android:name=".MyReceiver">
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>

Push notify doesn't arrive

I build an android app composed by a web view, in parse.com i've got my device registered but when i send a push notification in "pushes sent" there is 0 pushes.
this is my Mainactivity:
import com.party.bparty.MainActivity;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseQuery;
import com.parse.PushService;
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
private String url = "http://www.bestparty.altervista.org";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//attivo parse per le notifiche
Parse.initialize(this,"zJxpd9798Ns6A9rzUDpe78ElRY0I99ES3LD6nDQV","kmAmA1iTbC32BTE9ERtzNOoHXbJchhIn6tyPXKMi");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
//...
//...initializing and loading the contentview and the webview
}
//options menu omitted
}
this is my MycustomReceiver
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null)
Log.d(TAG, "Receiver intent null");
else {
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata")) {
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}
}
catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
and this is my ShowPopup
public class ShowPopUp extends Activity implements OnClickListener {
Button ok, cancel;
boolean click = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Cupon");
setContentView(R.layout.popupdialog);
ok = (Button)findViewById(R.id.popOkB);
ok.setOnClickListener(this);
cancel = (Button)findViewById(R.id.popCancelB);
cancel.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
finish();
}
}
And this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.party.bparty"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
<activity
android:name="com.party.bparty.ShowPopUp"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</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.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
Where's my error?
I do it, but it doesn't work anyway
" if (action.equals("com.party.bparty.UPDATE_STATUS")) {
Pick one, either com.party.bparty.UPDATE_STATUS or com.iakremera.pushnotificationdemo.UPDATE_STATUS"
but Now i have 1 "PUSH SENT" in push sent, but my device doesn't show any push
Your receiver has the wrong filter. Your receiver is declared as this:
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
but you are checking for a different intent action in the code:
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
Pick one, either com.party.bparty.UPDATE_STATUS or com.iakremera.pushnotificationdemo.UPDATE_STATUS and also make sure that Parse knows which one it is when you perform the push itself.

GCM message successfully sent but the smartphone android not received

I solved it but I no longer have the source code..sorry
I don't receive the notifications on my Android device. The messagge was sent successfully to the GCM servers. I tried them all. Can someone help me? This is the code:
GCMIntentService.java
public class GCMIntentService extends IntentService {
static SharedPreferences prefs;
static Editor editor;
Context context;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public static final String TAG = "GCM Intent Service";
public static final int NOTIFICATION_ID = 1;
public GCMIntentService() {
super(Configuration.SENDER_ID);
}
#Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
String msg = intent.getStringExtra("message");
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " +
extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i=0; i<5; i++) {
Log.i(TAG, "Working... " + (i+1)
+ "/5 # " + SystemClock.elapsedRealtime());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work # " + SystemClock.elapsedRealtime());
// Post notification of received message.
//sendNotification("Received: " + extras.toString());
sendNotification(msg);
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
editor.putInt("lastViewVisited", 1).commit();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getText(R.string.app_name).toString())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(intent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<MY-PACKAGE>"
android:versionCode="9"
android:versionName="2.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- GCM -->
<permission android:name="<MY-PACKAGE>.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="<MY-PACKAGE>.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- GCM -->
<receiver android:name="<MY-PACKAGE>.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" />
<category android:name="<MY-PACKAGE>" />
</intent-filter>
</receiver>
<service android:name="<MY-PACKAGE>.GCMIntentService" android:enabled="true" />
<activity
android:name="<MY-PACKAGE>.MainActivity"
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>
<activity
android:name="<MY-PACKAGE>.PreferenceFragment"
android:label="Preferenze">
</activity>
</application>
</manifest>
GcmBroadcastReceiver.java
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
Try:
Check if you are using the browser api key to send the message from web server to android devices.

Categories