谷歌云消息 - 通知USB行为 [英] Google Cloud Message - Notification USB Behavior

查看:163
本文介绍了谷歌云消息 - 通知USB行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语不是那么好......反正。

Sorry, my english is not so good... anyway.

我有一个使用GCM收到推送通知一个Android应用程序。

I have a android application that uses GCM to receive push notifications.

步骤:
1 - 用户点击登录按钮
2 - Android应用程序保存注册ID(工作)
3 - 发送给web服务,并把数据库(工作)
4 - 服务器应用程序(C#)发送选定的注册ID(工作)消息

Steps: 1 - User click logon button 2 - Android app save the registration ID ( Working ) 3 - Send to WebService and put in database ( Working) 4 - Server Application (C#) send the message for selected registration id ( Working)

5 - 设备接收通知正常,只是如果设备连接
在USB( * *问题

5 - Device receive the notification normally, BUT just if device is CONNECTED ON USB (* PROBLEM * )

如果我不连接在USB设备时,我收到通知,但有
空白的消息。

if i dont connect the device on usb, i receive the notification but with a blank message.

我正在阻止一个星期..有人能帮助我吗? PLZ ..

i'm blocked for one week .. someone can help me ? Plz..

公共类GCMNotificationIntentService扩展IntentService {

public class GCMNotificationIntentService extends IntentService {

public static  int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;

public GCMNotificationIntentService() {
    super("GcmIntentService");
}

public static final String TAG = "GCMNotificationIntentService";

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    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());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
                .equals(messageType)) {

            for (int i = 0; i < 3; i++) {
                Log.i(TAG,
                        "Working... " + (i + 1) + "/5 @ "
                                + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }

            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

            sendNotification(""+ extras.get(Config.MESSAGE_KEY));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

private void sendNotification(String msg) {
    Log.d(TAG, "Preparing to send notification...: " + msg);
    mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    long[] pattern = {500,500,500,500,500,500,500,500,500};

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Uri alarmSound2 = Uri.parse("android.resource://"  + getPackageName() + "/" + R.raw.mario);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, lucasbergamo.minha_granna.Android.ac_Login.class), 0);

    String date = DateFormat.getDateTimeInstance().format(new Date());

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)

            .setSmallIcon(R.drawable.coin_notification)
            .setContentTitle("Minha Granna - ")
            .setAutoCancel(true)
            .setLights(Color.BLUE, 500, 500)
            .setVibrate(pattern)
            .setSound(alarmSound2)
            .setStyle(new NotificationCompat.InboxStyle())
            .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);

    if (NOTIFICATION_ID > 1073741824) {
        NOTIFICATION_ID = 0;
    }

    mNotificationManager.notify(NOTIFICATION_ID++, mBuilder.build());
    Log.d(TAG, "Notification sent successfully.");
}

}

公共类GcmBroadcastReceiver扩展WakefulBroadcastReceiver {

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    ComponentName comp = new ComponentName(context.getPackageName(),
            GCMNotificationIntentService.class.getName());
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

}

<application
    android:name="lucasbergamo.minha_granna.Entidades.User"
    android:allowBackup="true"
    android:icon="@drawable/icones_indicador_financeiro"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >


    <activity
        android:name=".ac_Splash"
        android:label="@string/title_activity_splash" >
    </activity>
    <activity
        android:name=".ac_Login"
        android:label="@string/title_activity_splash" >

        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER"/>
            <action android:name="android.intent.action.MAIN"/>
        </intent-filter>


    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />


    <receiver
        android:name=".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="lucasbergamo.minha_granna.Notification" />
        </intent-filter>
    </receiver>

    <service android:name=".GCMNotificationIntentService" />


</application>

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />


<permission
    android:name="lucasbergamo.minha_granna.Notification.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />


<uses-permission android:name="lucasbergamo.minha_granna.Notification.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-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

我只接收如果USB电缆连接...如果不是我会收到空​​白邮件通知。

I receive the notification only if the usb cable is attached...if not i will receive blank message.

谢谢!!!!

bergamo86@gmail.com
Skype的lucazin

bergamo86@gmail.com skype lucazin

推荐答案

谢谢!包的名称是不同的!所以我解决这个问题,只设置当前包。

Thanks! the package name are different ! so i fix this issue just setting the current package.

谢谢大家!

这篇关于谷歌云消息 - 通知USB行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆