Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用parse时遇到的问题_Android_Parse Platform - Fatal编程技术网

Android 使用parse时遇到的问题

Android 使用parse时遇到的问题,android,parse-platform,Android,Parse Platform,我正在尝试制作一个应用程序,该应用程序正在使用parse library进行推送通知。我按照parse.com上的教程进行操作,但不起作用。 我得到一个错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.robotrackerclient/com.robotrackerclient.MainActivity}: java.lang.IllegalArgumentException: list

我正在尝试制作一个应用程序,该应用程序正在使用parse library进行推送通知。我按照parse.com上的教程进行操作,但不起作用。 我得到一个错误:

java.lang.RuntimeException: Unable to start activity 

ComponentInfo{com.robotrackerclient/com.robotrackerclient.MainActivity}: 

java.lang.IllegalArgumentException: listener==null
我想问题出在代码中。我有一个主活动,它正在启动应用程序的活动。我将parse.initialize()代码放在主活动的onCreate方法中。这是否造成了问题?还有一个错误:在使用解析库之前,必须调用parse.initialize(..)

主要的活动只是一个简单的类,获取当前位置的晶格度和经度并将其推送

         public class MainActivity extends Activity {
         private String imei_code_of_device;
         private LocationManager lm;
         private LocationListener locationListener;
         TelephonyManager mngr;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Specify an Activity to handle all pushes by default.
        //PushService.setDefaultPushCallback(this, MainActivity.class);

        Parse.initialize(this, "APP_KEY", "CLIENT_KEY"); 
        PushService.setDefaultPushCallback(this, MainActivity.class);

        mngr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        imei_code_of_device=mngr.getDeviceId();
        lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);               

        locationListener = new MyLocationListener();
        if ( !lm.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            buildAlertMessageNoGps();
        }
        else{

         lm.requestLocationUpdates(
         LocationManager.GPS_PROVIDER,
         10000,
         0,
         locationListener);
         lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,10000,0,locationListener);              

        }
        }
    private void buildAlertMessageNoGps() {

         final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                       public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                           startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                       }
                   })
                   .setNegativeButton("No", new DialogInterface.OnClickListener() {
                       public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                            dialog.cancel();
                       }
                   });
            final AlertDialog alert = builder.create();
            alert.show();

    }
    private class MyLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                ParseObject po=new ParseObject("LatLang");
                po.put("imei_code",imei_code_of_device);
                po.put("latitude",loc.getLatitude());
                po.put("longitude",loc.getLongitude());
                po.saveInBackground();
                Toast.makeText(getBaseContext(),"Location changed : Lat: " + loc.getLatitude() +" Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();

            }

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

     }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
这是我的androidmenifest文件: 在parse.com上提供的教程的帮助下,我完成了这些步骤。我包括了parse.com教程要求我包括的所有内容。我不明白应用程序的意义。因为我只需要在其中一个活动中进行解析,而且这不是第一个启动的活动。因此我不想在我的应用程序中初始化解析启动

       <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.robotrackerclient"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="16" />
<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.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <permission android:name="com.robotrackerclient.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.robotrackerclient.permission.C2D_MESSAGE" />

    <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>
        <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.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.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.robotrackerclient" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false">
        <intent-filter>            
        <action android:name="com.parse.push.intent.RECEIVE" />
        <action android:name="com.parse.push.intent.DELETE" />
        <action android:name="com.parse.push.intent.OPEN" />
         </intent-filter>
       </receiver>

       </application>
        </manifest>

您应该使用应用程序和客户端密钥,而不是此行中的默认值
app\u-KEY
client\u-KEY
Parse.initialize(此“应用程序密钥”、“客户端密钥”)


您可以在Parse注册后获得它。

好的,非常感谢您帮助我将push发送到Parse.com。错误出现在清单文件中。我更新了文件,在应用程序标记下提供了android:name=“ParseActivity”。然后我在ParseActivity类中定义了初始化。
现在,有人能告诉我如何使用同一组密钥通过服务器将推送的数据返回到另一台设备上吗?

我这样做了。我从parse.com获得了密钥。你能发布你的AndroidManifest.xml吗?