每次声明并运行两个服务时,我都会遇到以下binder.proxy异常.一个服务在不同的进程(专用于应用程序)中运行,另一个服务在与我的应用程序在(默认应用程序进程)中运行的同一进程中运行,具有Binder实现.
AndroidManifest.xml中:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.service.check"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:name="com.service.check.MainApplication"
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>
<service
android:name="com.service.check.SecondService"
android:exported="false"/>
<service
android:name="com.service.check.FirstService"
android:process=":newProcess" >
</service>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
我在按钮上的MainActivity中启动我的第一个服务,点击:
MainActivity.java
public class MainActivity extends ActionBarActivity implements OnClickListener {
private Button mLanchServiceBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLanchServiceBtn=(Button) findViewById(R.id.launch_btn);
mLanchServiceBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
//Starting first service
Intent …Run Code Online (Sandbox Code Playgroud) 我总是得到401错误.如果我正在使用我的本地服务器,任何人都可以让我确切地知道应该是什么HTTP引用者.即目前我正在使用:
http://localhost/GCM/index.php
Run Code Online (Sandbox Code Playgroud)
并使用它生成API访问密钥.
这是我的GCM请求的PHP代码.
$key='mykey';
$headers=array('Contenttype:application/json','Authorization:key='.$key);
$url = 'https://android.googleapis.com/gcm/send';
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode(array('field1' => 'some date','field2' => 'some other data',)),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
if($result==FALSE){
echo curl_error($ch);
echo curl_getinfo($ch);
}else{
echo $result;
}
Run Code Online (Sandbox Code Playgroud) php android google-api push-notification google-cloud-messaging