I set up GCM notifications successfully and can get the message from Server side success via GCM.
I also can show notification on notification bar system in android via these codes.
I try to show notification on lock screen by using these ways but not worked :
1 - Add <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
permission
2 - Add android:showOnLockScreen="true"
in main activity defined in manifest.xml
3 - Add into main Activity in java file :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
4 - Check Show notifications
check box in App Settings System already.
People who know how to show notification on Lock screen,
Please help me, I did so many searching but not help.
Thank you,
p/s :
I'm testing with Samsung S3, Android 4.3. Enable Lock screen page already.
I call show notification method from Intent Service
.
Codes show notification :
// Put the message into a notification and post it.
// This is just one simple example of what you might choose to do with
// a GCM message.
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, Pas.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK),
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_play_dark)
.setContentTitle("");
// Set Big View style to see full content of the message
NotificationCompat.BigTextStyle inboxStyle =
new NotificationCompat.BigTextStyle();
inboxStyle.setBuilder(mBuilder);
inboxStyle.bigText("");
inboxStyle.setBigContentTitle("");
inboxStyle.setSummaryText("");
// Moves the big view style object into the notification object.
mBuilder.setStyle(inboxStyle);
mBuilder.setContentText(msg);
mBuilder.setDefaults(Notification.DEFAULT_ALL);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
I use these permissions :
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.trek2000.android.pas.permission.C2D_MESSAGE" />
<permission
android:name="com.trek2000.android.pas.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.android.pas.Pas"
android:showOnLockScreen="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Receiver GCM -->
<receiver
android:name = "receiver.GcmBroadcastReceiver"
android:permission = "com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name = "com.google.android.c2dm.intent.RECEIVE" />
<category android:name = "com.trek2000.android.pas" />
</intent-filter>
</receiver>
<!-- Services -->
<service
android:name = "service.GcmIntentService"
android:exported = "true" />
</application>
minSdk=21
(android 5.0), so looks like not suitable, could you advise the other way? I already setsetVisibility
isPublic
, but it not worked. – Wickliffe