how to restart android avd? - android

i want to catch the BOOT_COMPLETED action in my program, how to restart the AVD??
thanks in advance.....
package com.alex.app.testsysaction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("receiver", "system reboot completed.......");
}
}
the AndrdoiManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alex.app.testsysaction"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
</manifest>

Install application on AVD.
Close it and then restart it again manually.It will catch reboot action

Related

BroadcastReceiver java.lang.ClassNotFoundException

I try to show a simple toast message on phone startup.
I wasted almost a day trying to figure out why my code did not work.
Here is the full error:
Unable to instantiate receiver com.debug.receivebootcomplete.debug.BroadcastReceiverClass: java.lang.ClassNotFoundException: com.debug.receivebootcomplete.debug.BroadcastReceiverClass
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.debug.receivebootcomplete.debug">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name">
<receiver android:name=".BroadcastReceiverClass" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
And my class:
namespace Debug
{
class BroadcastReceiverClass:BroadcastReceiver
{
public override void OnReceive (Context context, Intent intent)
{
Toast.MakeText (context,"Work",ToastLength.Short).Show ();
}
}
}
In emulator debug the application throw the java.lang.ClassNotFoundException and on phone when reboot the application crash.
Thank you in advance!
Thanks #Talha!
My error was generated by the intent-filter tag. I have no idea why because in every topic that I saw everybody used that tag in Manifest file.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
So I remove it and add
[BroadcastReceiver]
[IntentFilter(new[] {Intent.ActionBootCompleted})]
to the BroadcastReceiver class.

Android + Phonegap + Parse Push keeps crashing

I've been trying to make a simple Phonegap app that receives Parse Push notifications on Android.
I've read a number of tutorials and read through related issues here and elsewhere but i can't seem to get it to work without crashing.
I have the latest of Java JDK, Cordova + Node JS + plugman, Android API 19 (seems to be required by cordova), Apache ant, etc...
Bottom line: I can start the app. I can receive the notification just fine. But when I tap the notification to go back to the app it always crashes.
Question? Can anyone explain why this is happening? Or even better if you have a sample project that works? Any help would be greatly appreciated.
References:
https://parse.com/tutorials/android-push-notifications
http://www.raymondcamden.com/2012/10/10/PhoneGap-Parsecom-and-Push-Notifications -- a bit out of date
How do I get Parse.com Push Notifications working in a Cordova/Phonegap Android app?
apache cordova app crashes after receiving parse.com push notification
Sources:
AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.company.challenger" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.company.challenger.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.challenger.permission.C2D_MESSAGE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:name="com.company.challenger.ChallengerApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/app_name" android:launchMode="singleTop" android:name="ChallengerApplication" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<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.company.challenger" />
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.parse.ParsePushBroadcastReceiver">
<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>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
CordovaApp.java
package com.company.challenger;
import com.parse.ParseAnalytics;
import android.os.Bundle;
import org.apache.cordova.*;
public class CordovaApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
ParseAnalytics.trackAppOpened(getIntent());
}
}
ChallengerApplication.java
package com.company.challenger;
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
import com.company.challenger.CordovaApp;
public class ChallengerApplication extends Application
{
private static ChallengerApplication instance = new ChallengerApplication();
public ChallengerApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
#Override
public void onCreate() {
super.onCreate();
// register device for parse
Parse.initialize(this, "app key", "client key");
PushService.setDefaultPushCallback(this, CordovaApp.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
Proper answer this time...
I basically started from scratch following the latest parse tutorial and making sure the initialize parse in the MainApplication and not in your javascript.
This is the gist:
Create a MainApplication.java with a skeleton like this:
package com.{your_company}.{your_app};
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParsePush;
import com.parse.SaveCallback;
import com.parse.ParseException;
import com.{your_company}.{your_app}.MainActivity;
public class MainApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
// parse initialization goes here
}
}
Add the following attribute to your application tag in AndroidManifest.xml
<application ... android:name="com.{your_company}.{your_app}.MainApplication">
Follow this tutorial from Parse.com which is fairly decent https://parse.com/tutorials/android-push-notifications .
The final onCreate in MainApplication.java should look something like this:
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(app);
Parse.initialize(app, "{app_key}", "{client_key}");
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
From this experience I found the following insights:
Not recommended to use any parse push plugins floating around because
there are all out of date using deprecated calls or simply did not
work out of the box.
The Parse initialize must occur in the MainApplication and cannot occur in the javascript. (I don't have the reference for this one, I came
across it somewhere down the line when frantically researching).
Always use the latest Parse SDK and use ParsePush (the new service) and not PushService which is depricated.
Hopefully this helps.

my first android app doesn't running after successful installation

I am making an android app. the first launcher activity code is :
package com.example.test;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
public class FirstPage extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sp = getSharedPreferences("STATE",0);
String x = sp.getString("typeOfUser","");
if(x==""){
setContentView(R.layout.activity_first_page);
Intent intent = new Intent(this,LoginOrRegister.class);
startActivity(intent);
}
else {
setContentView(R.layout.lat_lon);
}
}
}
Manifest file is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:maxSdkVersion="19" android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test.FirstPage"
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=".LoginOrRegister" />
<activity android:name="Registration"></activity>
<activity android:name="SignIn"></activity>
</application>
</manifest>
But when running this app. there is error: :
No command output when running: 'am start -n com.example.test/com.example.test.FirstPage -a android.intent.action.MAIN -c android.intent.category.LAUNCHER' on device emulator-5554
this is my stack trace:
com.android.ddmlib.ShellCommandUnresponsiveException
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:430)
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:347)
at com.android.ddmlib.Device.executeShellCommand(Device.java:584)
at com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction(ActivityLaunchAction.java:67)
at com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction(ActivityLaunchAction.java:109)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.doLaunchAction(AndroidLaunchController.java:1293)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.doLaunchAction(AndroidLaunchController.java:1305)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launchApp(AndroidLaunchController.java:1277)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.simpleLaunch(AndroidLaunchController.java:913)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.continueLaunch(AndroidLaunchController.java:755)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(AndroidLaunchController.java:575)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.doLaunch(LaunchConfigDelegate.java:330)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:246)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Could be a duplicate of one of these questions, which have to do with the same ShellCommandUnresponsiveException exception shown in the stack trace:
Android CTS is showing ShellCommandUnresponsiveException on emulator
Android App Won't Display in Emulator

Device disconnects after a call

I'm trying to write a simple broadcast receiver that captures voice calls. Below is my receiver class and manifest file. Every time I try to run it, my virtual device gets disconnected right after a call. What am I doing wrong???
package com.example.example06;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class MyPhoneReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "A phone call was received!", Toast.LENGTH_LONG).show();
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example06"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name="MyPhoneReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>
</application>
</manifest>
Maybe change manifest to :
<receiver
android:name="com.example.android.blah.MyPhoneReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" ></action>
</intent-filter>
</receiver>

BroadcastReceiver's behaviour for ACTION_SHUTDOWN

I have BroadcastReceiver which listens for ACTION_SHUTDOWN and some other actions.
My problem is, when I shutdown my android device(2.3.6) BroadcastReceiver is catching ACTION_SHUTDOWN two times. Problem is only with ACTION_SHUTDOWN and not with other actions.
When I run same code on emulator, it works fine.
Guys please help me. Here is my code:
my BootReceiver.java
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_SHUTDOWN.equalsIgnoreCase(intent.getAction())) {
Log.i("Boot Receiver - Shutdown event");
// database operation
}
if(Intent.ACTION_BOOT_COMPLETED.equalsIgnoreCase(intent.getAction())) {
// some operation
}
if(Intent.ACTION_AIRPLANE_MODE_CHANGED
.equalsIgnoreCase(intent.getAction().intern())) {
// some operation
}
if(ConnectivityManager.CONNECTIVITY_ACTION
.equalsIgnoreCase(intent.getAction())) {
// some operation
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.ui"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/spota"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.xyz.UserActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.xyz.BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.BATTERY_CHANGED" />
<action android:name="android.intent.action.AIRPLANE_MODE"/>
</intent-filter>
</receiver>
</application>
And here is the Logcat entries
05-03 16:37:23.826: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:23.881: I/xyz(2337): Inserting Data
05-03 16:37:28.514: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:28.529: I/xyz(2337): Inserting Data
Thanks!
you can add a flag to avoid this.
once you received this intent, set the flag.
if(flag)
{
do sth.
flag =0 ;
}
else
{
ignore.
}

Categories

Resources