Can't get Parse.com framework to work - android

I've been trying to put data to Parse Cloud for days and I can't really figure out why it is not working.
I included both libs (Parse and bolts-android) and followed several tutorials on the web. My code is as following:
package com.dannyvdz.testapp2;
import android.app.Activity;
import android.os.Bundle;
import com.parse.Parse;
import com.parse.ParseObject;
public class ParseApplication extends Activity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.parseapplication);
Parse.initialize(this, "************", "************");
// Test creation of object
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dannyvdz.testapp2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".ParseApplication"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The app compiles and runs without errors but no code is being sent to Parse.com. I tried both running the app from Android studio and running it after building it installing it using adb. I can't seem to figure out what I am doing wrong. Any help would be greatly appreciated since I think my hairs starting to go grey because of this...

are you sure you have internet connection on the (emulator or your device) ??
can you try:
testObject.saveEventually();
change it with:
testObject.saveInBackground();

I'm not sure as to why but the application works on my tablet and the android emulator so the problem is my phone. I guess I should factory reset my phone (or wait for my new nexus 6 and work with my tablet in the meantime).
Thanks for all the help!
Update: Several days later I checked Logcat again and I found some messages which make me think of my android adblocker (adfree). I disabled adfree and it started working again. At least I figured it out!

Related

AWS Cognito Integration

I am working to integrate the Login Screen of an application I am working to create with AWS Cognito and have been following the step by step instructions to connect with the server.
STEP 5 OF 7
Copy the Mobile Hub Helper and Custom Code
Copy the src/main/java/com/amazonaws folder from the code you downloaded into the java/com folder of your Android Studio project.
This folder contains a set of helper classes that have been custom generated for you. These were generated based on your project configuration and on the AWS cloud resources and identifiers that were created for you when you configured the project. These classes simplify the use of all the SDKs that are required to support your project.
It also contains the source code for the AWSMobileClient which is a singleton component which bootstraps the app and creates an identity manager to establish the user identity with Amazon Cognito. If your project uses the Mobile Hub NoSQL feature the AmazonAws folder will also contain model classes that simplify your access to the DynamoDB tables you configured.
I believe I am running into problems with the last half of this bit as I am unsure what a singleton component is or how to insert it into the code. I have created it as a Java class and included the included code
package com.your.app;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import com.amazonaws.mobile.AWSMobileClient;
/**
* Application class responsible for initializing singletons and other common components.
*/
public class Application extends MultiDexApplication {
private final static String LOG_TAG = Application.class.getSimpleName();
#Override
public void onCreate() {
Log.d(LOG_TAG, "Application.onCreate - Initializing application...");
super.onCreate();
initializeApplication();
Log.d(LOG_TAG, "Application.onCreate - Application initialized OK");
}
private void initializeApplication() {
// Initialize the AWS Mobile Client
AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());
// ... Put any application-specific initialization logic here ...
}
}
however I get a red line in the manifest because it is not connected to an XML file, however the instructions never say to add an XML or to attach it to an XML file so im not sure how to connect these features. I imagine that the Application class should be populated following startup i.e. App opens to the login screen and it somehow initiates the communication with the server to transmit the strings which are typed into the text fields.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jason.mvp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity" android:theme="#style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Application"/>
<activity android:name=".MainActivity" />
<activity android:name=".RegisterActivity" android:theme="#style/NoActionBar"
android:parentActivityName="com.example.jason.mvp.LoginActivity" >
</activity>
</application>
</manifest>
can anyone help me!? Thank you!
Jessy,
It looks like you didn't do step 7 yet or did it wrong? Rather than have .application as an activity you should instead add it directly under application:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.example.jason.mvp.Application">
Have you started the integration steps for "User Sign-In" yet? You have to walk through those steps as well. One way to display the login view is to use a splash activity as is discussed in step 3 of the user sign-in integration steps.
Kevin

Custom permission in Android

I'm trying to figure out how to work with custom permissions in Android.
https://developer.android.com/guide/topics/manifest/manifest-intro.html#perms .
I found similar problems answered here but none of the answers worked for me...
I've created simple app with Android studio 2.1.1
package com.example.lukas.permtest;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
with manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lukas.permtest">
<permission android:name="com.example.lukas.permission.ACTIVITY_PERM"
android:label="#string/permlab_activity"
android:description="#string/permdesc_activity"
android:protectionLevel="normal"/>
<uses-permission android:name="com.example.lukas.permission.ACTIVITY_PERM"/>
<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"
android:permission="com.example.lukas.permission.ACTIVITY_PERM">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I have Sony Xperia Z2 tablet with Andoid 4.4.2 and Xperia Z3+ With Android 6.0
The app doesn't work. I get the same exception for both devices...
W/ActivityManager: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.lukas.permtest/.MainActivity } from ProcessRecord{44cf1178 2461:com.sonyericsson.home/u0a95} (pid=2461, uid=10095) requires com.example.lukas.permission.ACTIVITY_PERM
What am I doing wrong?
Thanks
Hah! That's pretty funny!
I believe that what is going on here is that, although you've done everything right as far as your process and the permission, you forgot one small thing...
The Launcher needs to start your app. The Launcher doesn't have your custom permission.
In other words, your application could launch its own MainActivity, because it has the permission to do so. The Launcher does not have the permission, so when it attempts to launch the android.intent.action.MAIN Activity, if fails for lack of permission.
Separate the Main Activity from the Activity protected by the permission. Launch the protected Activity from the Main Activity and everything go smooth as silk.

The Crosswalk framework for Android

I have a few questions about Crosswalk, I tried searching on Google, but since I don't know the exact names of some functions, I can't find anything.
Is it possible to use Crosswalk to render a online website?
If the answer to question 1 is no, Is it possible to write a HTML5+JS app, that renders an iframe, with in there a online site?
If question 1 is yes, can you post a link to a documentation or a tutorial?
Yes it is possible to do both action.
here is some help on the official web site. and here is a code that might work for you too
import android.app.Activity;
import android.os.Bundle;
import java.util.logging.Logger;
import org.xwalk.core.XWalkView;
public class MainActivity extends Activity {
/**
* Called when the activity is first created.
*/
Logger logger = Logger.getLogger("xwl");
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
XWalkView view = new XWalkView(this, this);
logger.severe("loadeding ...");
view.load("https://www.google.com", null);
logger.severe("loaded");
setContentView(view);
}
}
Here is the manifest file
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wxl"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher" android:hardwareAccelerated="true"
android:largeHeap="true">
<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>
</application>
</manifest>
The two permissions are needed.
The only problem I found is that it renders blurry :( on android.
Good luck.

App refuses to connect to Parse backend

I am working on an app called TobaccoRoad that uses a library project called BestApproach. It uses a Parse backend to display custom generated content and handle push notifications. Everything was working pretty alright until a few days ago, when I must have messed up some settings somewhere and it no longer seems to be making the connection to the parse systems. I'm quite sure it's a local issue, because my second tester phone, which has not had updated code pushed to it in a few days, is still receiving notifications and can view that custom content.
The weird thing is, even after clearing my workspace and starting fresh from the (definitely good) code my employer gave me, and following all the tutorials and troubleshooting guides on Parse.com (see https://parse.com/docs/push_guide#installations/Android; https://parse.com/tutorials/android-push-notifications) I'm still not connecting to Parse. I haven't made any significant changes that I can recall, so I'm at a loss as to what might be causing this.
I know it's not an issue of a bad applicationID or clientKey, because even substituting random strings into the Parse.initialize call gave the same results, and a logcat error about not being able to authenticate.
Here are the relevant bits from my manifest files, first for the library project...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestapproach.lib"
android:versionCode="8"
android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name"
android:theme="#style/Theme.BA" >
<activity android:name="com.bestapproach.lib.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="#style/Theme.BA.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Declarations for all of my Activities...-->
<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>
</application>
</manifest>
And the manifest is exactly the same for my dependent project, with the exception of where I define a custom receiver at the end:
<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.bestapproach.lib.MyCustomReceiver">
<intent-filter>
<action android:name="com.bestapproach.lib.UPDATE_STATUS" />
</intent-filter>
</receiver>
And here's the code for the onCreate() method in my main activity (SplashActivity) where the Parse service is initialized:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
String parseClientId = getString(R.string.parse_client_id);
String parseAppId = getString(R.string.parse_app_id);
//debug output
Log.v("parse should be initializing...", parseAppId+" "+parseClientId);
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
PushService.subscribe(this, "", MenuActivity.class);
PushService.setDefaultPushCallback(this, SplashActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
final Activity a = this;
// Fetches content if it doesn't exist.
StoreManager sm = StoreManager.getInstance(a);
ParseStoreManager psm = ParseStoreManager.getInstance(a);
return;
}
}
Suggestions I've found that seem like they may be on track with what I need include running Parse.initialize() in the onCreate() of every activity, which I don't really want to do as there are a lot of them and that would be a lot of duplicated code, or generating an Application object and running it from there. Everything I've tried in relation to that has ended up breaking once I add it to my manifest file, due to TobaccoRoad's dependencies on the library project.
I know, it's a lot to dig through, but any suggestions would be appreciated. Thanks everybody.
Possible fix:
Change this line
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
to this:
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(SplashActivity.this, parseAppId, parseClientId);
the issue is that
ParseAnalytics.trackAppOpened(getIntent());
accepts the intent from that activity from your SplashActivity and from the application scope
Also, you initialize parse from the activity which we generally don't do.
We try initialize parse from the Application class so it has the context of the Application scope and not of the Activity Scope.
I recommend you to create an Application class and include the parse code in the onCreate of the Application...which you would need to do only once.
Or, you can create some BaseActivities and make all your activities in the application extend to that. This will save you from writing duplicate code...this is just in case you are bound not to create an Application class.
Pardon me for anything wrong...I am new in answering.

Start FtpServer when charging the Phone

i want to make an App which starts an FTPServer when my Phone is conncted to Power. I dont want my App to have an GUI.
In GooglePlay i found an 3rd Party FtpServer App which can be started and stopped via Intent
Intents:
com.theolivetree.ftpserver.StartFtpServer
com.theolivetree.ftpserver.StopFtpServer
So i would like to use those codes in my app to execute those commands but i dont have any clue how to use them. So far i am trying to use Toast to look if anything happen before i move further, but unfortunally nothig happens.
my AndroidManifest.XML looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.power.ftpserver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:allowBackup="true">
<receiver android:enabled="true" android:name="FtpReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"> </action>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"></action>
</intent-filter>
</receiver>
</application>
</manifest>
FtpReceiver.java
package de.power.ftpserver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class FtpReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context , Intent intent)
{
String action = intent.getAction();
if(action.equals(Intent.ACTION_POWER_CONNECTED))
{
Toast.makeText(context, "FtpServer gestartet", Toast.LENGTH_LONG).show();
}
else if(action.equals(Intent.ACTION_POWER_DISCONNECTED))
{
Toast.makeText(context, "FtpServer beendet", Toast.LENGTH_LONG).show();
}
}
}
When i install the App to my Phone the Console says
[2013-08-02 12:28:19 - FtpServer] No Launcher activity found!
[2013-08-02 12:28:19 - FtpServer] The launch will only sync the application package on the device!
but installs anyway. I can Plug in and Out the Powerconnectioncable but i dont get any Toast Messages. Can anyone help plz?
I know this is a bit old. But just for future reference and as a partial solution, I had the same problem of how to use the Intents provided by the FTP Server app, this is what you're looking for:
Intent startIntent = new Intent("com.theolivetree.ftpserver.StartFtpServer");
sendBroadcast(startIntent); // start
And to stop, it's the same
Intent startIntent = new Intent("com.theolivetree.ftpserver.StopFtpServer");
sendBroadcast(startIntent); // stop
Hope it still can help someone.

Categories

Resources