Unable to connect android application to parse - android

I am trying to connect my android application to parse.com but I am stuck at last step.On Parse website it is mentioned Add the following to your ApplicationonCreate():
Parse.enableLocalDatastore(this);
Parse.initialize(this, "yDdwwIjw0jmTnTEAzc3CQaXXXXXXXXXXXX", "kljfnAt3XXXXXXXXXXXX");
I am unable to understand how and where to add this code.Please guide through the steps.

Create Application class inside main package
public class MyApplication extends Application{
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key));
}
}

Add permissions to your Manifest file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Create a class which extends the Application class
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, getString(R.string.parse_application_id), getString(R.string.parse_client_key));
}
}
Don't forget to add android:name=".MyApp" to the application in your Manifest file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name=".MyApp" >
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Related

chrisjenx/calligraphy not work properly in my app tried so many answered

I tried so many examples and answered from other questions on this library but not working for me. I don't know what was happened with this?
Application class :
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/choco-cookie.ttf")
.setFontAttrId(R.attr.fontPath)
.build());
}
}
AndroidManifest.xml :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".Utils.MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Design.DashboardActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Also attached to Activity :
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
And font available in 'assets/fonts/choco-cookie.ttf'.
Problem is not changing fonts of all over app!
Make sure you register your custom Application in the Manifest
<application
android:name=".MyApplication" <----------- HERE
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">

Unable to access permission(s) within java code from manifest

manifest.java :
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mfi;
public final class Manifest {
public static final class permission {
public static final String C2D_MESSAGE="permission.C2D_MESSAGE";
}
}
AndroidManifest.xml :
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GPS_PROVIDER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
But I'm unable to request any permissions from MainActivity as below code throws compiler error L: cannot resolve symbol : ACCESS_FINE_LOCATION
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
1);
How to update manifest.java to generate the permission I'm attempting to access, in this case Manifest.permission.ACCESS_FINE_LOCATION ?
Import the below package for Manifest class,
import android.Manifest;
You can easily access the permission Manifest.permission.ACCESS_FINE_LOCATION and others too

Cannot cast class when using Google Analytics in Eclipse

I think I have all the elements right in my Eclipse projects but I still receive this error:
java.lang.ClassCastException: android.app.Application cannot be cast
to cam.main.AnalyticsApplication
Here's the AnalyticsApplication code:
package cam.main;
public class AnalyticsApplication extends Application {
private Tracker tracker;
public AnalyticsApplication() {
super();
}
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
tracker = analytics.newTracker(R.xml.analytics);
}
return tracker;
}
}
Here's the Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cam.main"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="6"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="#drawable/bot_img_1"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="cam.main.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<- other activities from the app ->
</application>
<application android:name="cam.main.AnalyticsApplication">
</application>
</manifest>
And I have this code on the OnCreate method of my starting activity (StartMenu)
AnalyticsApplication application = (AnalyticsApplication) getApplication();
Tracker mTracker = application.getDefaultTracker();
I don't know if it's important but I have AnalyticsApplication and StartMenu in the same file.
Is there a need to create an Activity inside the AnalyticsApplication or something?
Just include your android:name="cam.main.AnalyticsApplication" parameter to an exist application tag like this:
<application
android:name="cam.main.AnalyticsApplication"
android:icon="#drawable/bot_img_1"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="cam.main.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<- other activities from the app ->
</application>
Your custom Application class works incorrectly because of 2nd tag.

Fatal Exception applicationId is null Parse

This is my second question in SO, I have a problem about Fatal Main error. Before I ask it, I found some other problem in SO, but what I found is about Facebook app
This is my error
java.lang.RuntimeException: applicationId is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
But, I have a class that declared it
package com.example.michael.eksperimen6chatting;
import android.app.Application;
import com.parse.Parse;
/**
* Created by Michael on 03/12/2015.
*/
public class ChattApp extends Application
{
#Override
public void onCreate()
{
super.onCreate();
Parse.initialize(this, "urkcFwvUmgSYvuOFTInJmkA3iWv0ArV3XT128TNb", "WvBC0cnGXHkVhTBbkFwLyxGDRgqR6qC8ft7DIleT");
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.michael.eksperimen6chatting" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
</activity>
<activity android:name=".UserList"></activity>
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chat">
</activity>
</application>
</manifest>
Did I miss something here, can anyone help me? Gratia
Specifying ChattApp Application class name in your AndroidManifest.xml's <application> tag.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:name="com.example.michael.eksperimen6chatting.ChattApp">
....
</application>
import com.parse.Parse;
import android.app.Application;
public class ChattApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
}
AndroidManifest.xml
<application
android:name="com.example.michael.eksperimen6chatting.ChattApp"
.
.
.
</application>

SecurityException at starting intent of a new empty Activity

I have developed a little project using just one Activity, and now, I'm trying to add a new one, but, I recieve this error when I'm trying to launch the project on my device:
Running com.android.gl2jni/.TestActivity... 1> Starting: Intent {
cmp=com.android.gl2jni/.TestActivity } 1> 1>
java.lang.SecurityException: Permission Denial: starting Intent {
flg=0x10000000 cmp=com.android.gl2jni/.TestActivity } from null
(pid=2935, uid=2000) requires null
I'm not trying to call the new Activity, and I have developed an empty Activity to check why I can't launch the app.
This is my Manisfest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.gl2jni">
<uses-feature android:glEsVersion="0x00020000"/>
<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:label="#string/gl2jni_activity">
<!--main activity-->
<activity android:name=".GL2JNIActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:configChanges="keyboardHidden"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--BT device list activity-->
<activity android:name=".TestActivity"
>
<intent-filter>
</intent-filter>
</activity>
<!--
<activity android:name=".BluetoothDeviceListActivity"
android:label="#string/select_device"
android:theme="#android:style/Theme.Dialog"
android:configChanges="keyboardHidden"
android:screenOrientation="landscape"
/>
-->
</application>
</manifest>
And this is the empty activity class:
package com.android.gl2jni;
import android.app.Activity;
import android.util.Log;
import android.os.Bundle;
public class TestActivity extends Activity {
#Override protected void onCreate(Bundle icicle) {
LogConsole.print( "HI, I AM TestActivity" );
}
}
I suppose that I have to modify something else more, but I don't know what...
Thanks in advance for the help.
You've specified an empty intent filter for TestActivity. An empty intent filter matches NO intents. Remove these lines from the block for TestActivity:
<intent-filter>
</intent-filter>
Also, in onCreate() of TestActivity you must call super.onCreate(), otherwise Android will crash it.

Categories

Resources