- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我尝试从 Google 获取我的 GCM registrationId。
我的代码:
String SENDER_ID = "722******53";
/**
* Registers the application with GCM servers asynchronously.
* <p>
* Stores the registration ID and the app versionCode in the application's
* shared preferences.
*/
private void registerInBackground() {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered, registration ID=" + regid;
// You should send the registration ID to your server over
// HTTP, so it
// can use GCM/HTTP or CCS to send messages to your app.
sendRegistrationIdToBackend();
// For this demo: we don't need to send it because the
// device will send
// upstream messages to a server that echo back the message
// using the
// 'from' address in the message.
// Persist the regID - no need to register again.
storeRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
mDisplay.append(msg + "\n");
}
}.execute(null, null, null);
}
我得到一个错误:
03-01 19:15:36.261: E/AndroidRuntime(3467): FATAL EXCEPTION: AsyncTask #1
03-01 19:15:36.261: E/AndroidRuntime(3467): java.lang.RuntimeException: An error occured while executing doInBackground()
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$3.done(AsyncTask.java:299)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.lang.Thread.run(Thread.java:841)
03-01 19:15:36.261: E/AndroidRuntime(3467): Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1800)
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.app.ContextImpl.startService(ContextImpl.java:1772)
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.content.ContextWrapper.startService(ContextWrapper.java:480)
03-01 19:15:36.261: E/AndroidRuntime(3467): at com.google.android.gms.gcm.GoogleCloudMessaging.b(Unknown Source)
03-01 19:15:36.261: E/AndroidRuntime(3467): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
03-01 19:15:36.261: E/AndroidRuntime(3467): at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:177)
03-01 19:15:36.261: E/AndroidRuntime(3467): at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:1)
03-01 19:15:36.261: E/AndroidRuntime(3467): at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-01 19:15:36.261: E/AndroidRuntime(3467): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-01 19:15:36.261: E/AndroidRuntime(3467): ... 4 more
这是我的 list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.manyexampleapp"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<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.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE" />
<permission
android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name="com.zoomer.ifs.BaseApplication"
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" />
<activity
android:name="com.zoomer.ifs.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop">
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</activity>
<!-- PUSH -->
<!--
WakefulBroadcastReceiver that will receive intents from GCM
services and hand them to the custom IntentService.
The com.google.android.c2dm.permission.SEND permission is necessary
so only GCM services can send data messages for the app.
-->
<receiver
android:name="com.example.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.manyexampleapp" />
</intent-filter>
</receiver>
<service android:name="com.example.gcm.GcmIntentService" />
<activity
android:name="com.example.gcm.DemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- DB -->
<activity
android:name="com.example.db.DbActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
<activity
android:name="com.example.http.RestGetActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name="com.example.fb.FacebookLoginActivity"
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.example.http.SendFeedbackActivity"
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.zoomer.general.SearchNearbyOffersActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.example.manyexampleapp.StoresListActivity" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.example.fb.ShareActivity" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.example.notifications.NotificationsActivity" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.example.fb2.no_use.MainActivity" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name="com.zoomer.offers.OffersListActivity" >
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity android:name="com.example.http.SearchNearbyOffersActivity" >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> -->
</activity>
<service
android:name="com.example.geo.LocationService"
android:enabled="true" />
<receiver android:name="com.example.manyexampleapp.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.example.manyexampleapp.LocationService.LOCATION_BROAD_MSG" />
</intent-filter>
</receiver>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
</application>
</manifest>
最佳答案
改变
<uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" />
到
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
您收到异常是因为您没有定义所需的权限
关于java - SecurityException : Not allowed to start service Intent { act=com. google.android.c2dm.intent.REGISTER pkg=com.google.android.gms(有附加功能)},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22117317/
我编写了一个小型库,我正在尝试将其设置为可与 pkg-config 一起使用,以供我组织中稍后可能需要使用它的人使用。所以我的安装程序在/usr/local/lib/pkgconfig 中放置了一个
我已经通过brew安装了pkg-config和libusb 现在如果我这样做 pkg-config --cflags --libs libusb 我收到以下消息 Package libusb was
我试图更新我的 julia 软件包,但遇到了问题。首先,我跑了Pkg.update()一如既往... julia> Pkg.update() INFO: Updating METADATA... IN
为了创建 .pkg 文件,我使用“Packager.app”。我使用格式 - '平面' 创建项目。当我尝试使用下一个命令签署 .pkg 文件时 productsign --sign“开发者 ID 应用
我有两个模块在一个包下形成循环导入 /test __init__.py a.py b.py a.py import test.b def a(): print("a") b.py im
我正在为需要 NodeJS 的产品构建 OS X .pkg 安装程序。 我正在尝试嵌入 official NodeJS pkg installer 的可能性作为我的安装程序的组件包。 我将官方 pkg
我正在与 OSX 的 packageMaker 作斗争,因为它不允许我创建“.pkg”。相反,它迫使我制作一个“.pkg.mpkg”。 这似乎是一个愚蠢的问题,我应该可以通过几次谷歌搜索来回答,但我无
我正在使用 Comparator对 List 进行排序通过它的属性(类型为 Date )在 viewscoped 托管 bean 中。 问题是我一直收到 ClassCastException如下- j
我尝试使用 travis-ci 检查我的 r 包是否正确。我的包应该导入 r pkg nloptr。而 travis-ci 会在 "r": "oldrel"分支给出错误。我在这里显示错误: confi
我尝试安装 udev。 udev 在 ./configure 期间给我一个错误 --exists: command not found configure: error: pkg-config and
我发现 sudo apt-get install python-和 sudo pip3 install 在不同的地方安装文件。 有没有办法通过对用户透明的两个选项中的任何一个来渲染安装? 在我的特殊情
我已经阅读了几篇关于这个的帖子。 但是他们并没有从我这里解决。 请看资料 brew install pkg-config 完成安装然后 Rangers-iMac:dash ranger$ which
我安装了最新的 anaconda2。我发现 anaconda2/Lib/site-packages/ 中存在相同的包和 anaconda2/pkgs/ . python中调用的区别和pkgs有什么区别
我正在编写一个大小开始增长的 R 包,因此非常感谢在文件夹 pkg/R/和(尤其是)在 pkg/src/中使用自定义结构。 例如,假设我有两个类型 A 的算法系列和一些类型 B 的函数,以及一个主入口
今天在使用 brew reinstall python 在 homebrew 上重新安装 Python 2 之后发生了一件有趣的事情。 异常 Traceback (most recent call l
摘要:最新的 GlassFish 4.1.2 中缺少 pkg-bootstrap.jar 和相关文件,这导致 updatetool 无法运行。在 Windows 10 上安装和运行 updatetoo
我正在尝试创建一个 bash 脚本来自动创建应用内购买 pkg 文件。 我正处于脚本成功创建所有应用内购买 xcodeproj 项目然后使用此命令将它们存档 xcodebuild -scheme $n
有人知道包含 arm-linux-androideabi-pkg-config 工具的 ffmpeg linux arm 平台的任何工具链吗? Android NDK 不包含它。还有人成功地为包含 a
我有以下文件: pkg/__init_.py pkg/module.py 现在,在 pkg/__init__.py 中,如何导入 module? 是吗 import pkg.module 或 impo
我正在使用 Stack 和 Nix 构建一个 Haskell 项目,并依赖于来自 Hackage 的 cairo 库。 当我构建项目时,出现错误:无法找到 pkg-config >= 0.9.0 或
我是一名优秀的程序员,十分优秀!