Android app will not run - java

So I am trying to run this app I am using to learn about threads and intents however the app will not run, But I don't have any warning/error underlines in the code, could anyone help me please.
Manifest code:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.learn.tam.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.learn.tam.StartingPoint"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
and Activity code
package com.example.learn.tam;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try {
sleep(5000);
}
catch (InterruptedException e){
e.printStackTrace();
}
finally{
Intent openStartingPoint = new Intent("com.example.learn.tam.StartingPoint");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
any help would be appreciated please

Change
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Since your app is probably not shown on the home screen (the MAIN category is needed).
And also change
Intent openStartingPoint = new Intent("com.example.learn.tam.StartingPoint");
startActivity(openStartingPoint);
to
Intent openStartingPoint = new Intent(Splash.this, StartingPoint.class );
startActivity(openStartingPoint);
Since your StartingPoint does not define an Intent-Action with "com.example.learn.tam.StartingPoint"
See if that fixes anything.

Remove this:
<action android:name="android.intent.action.SPLASH" />
And replace it with this:
<action android:name="android.intent.action.MAIN" />

Related

Receiving call intent in broadcast receiver

I want to get the called number in android but When I start the outgoing call it fails I am using broadcast receiver and register it in service to keep listen if activity not in focus here is my code.
Menifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vampirepc.androidservice" >
<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" />
<action android:name="android.intent.action.BOOT_COMPLETED">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</action>
</intent-filter>
</activity>
<service android:name=".MyService" />
<receiver
android:name="com.example.vampirepc.androidservice.OutgoingReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>
BroadcastReceiver Class
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(ctx,
"Inside broadcast",
Toast.LENGTH_LONG).show();
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();
}
Service
#Override
public void onCreate() {
Toast.makeText(getApplicationContext(),"Service created",Toast.LENGTH_SHORT).show();
try {
IntentFilter filter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
OutgoingReceiver myReceiver = new OutgoingReceiver();
registerReceiver(myReceiver, filter);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Exception is "+String.valueOf(e),Toast.LENGTH_SHORT).show();
}
}
Have a look at this
Phone state Broadcaster
Please add the permission in the top ,this helped me
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vampirepc.androidservice" >
android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_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" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.BOOT_COMPLETED">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</action>
</intent-filter>
</activity>
<receiver
android:name="com.example.vampirepc.androidservice.OutgoingReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<service android:name=".MyService" />
</application>
<uses-permission
</manifest>
Have you realized in this line:
Toast.makeText(ctx,
"Inside broadcast",
Toast.LENGTH_LONG).show();
You used ctx instead of context.
Thank to all i have solved the problem my self I was using incorrect context in toaster the correct onReceive is.
I was using ctx which was initialize.
Context ctx;
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG).show();
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();
}

Android: start activity on boot complete

I have tried this on a few android phones with no luck (i did start the app once).
This was mostly generated from android studio 1.3.2 and from some questions like this and that and the other.
Perhaps someone can point out what i am doing wrong.
Thanks
edit: moved receiver inside app, but no joy.
edit2: added missing permissions for receiver. now seems to work on a nexus 4. but not on the kindle fire or the at&t tablets. although it seems to come right away if i press the circle icon on the azpen.
edit3: seems to work sometimes on the fires now.
package acme.startup;
import android.content.*;
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent activityIntent = new Intent(context, MainActivity.class);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activityIntent);
}
}
}
package acme.startup;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
if(id==R.id.action_settings)
return true;
return super.onOptionsItemSelected(item);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="acme.startup" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name=".BootReceiver"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<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>
Every Component must be declared inside application tag into manifest. Here you declared receiver outside of application tag. Read Structure of the Manifest File.
Correct manifest wil be
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="acme.startup" >
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<receiver
android:name=".BootReceiver"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
You have to add permission to manifest file. Add this before your <application> tag :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Android service turns red

I want to add a service to my manifest but it gives a warning in.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aura_apps.tygo_asbroek.intentexample" >
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<activity
android:name=".SecondActivity"
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=".TygoIntentService"
>
</service>
</application>
Here is the Java code:
package com.aura_apps.tygo_asbroek.intentexample;
public class TygoIntentService extends IntentService {
private static final String TAG = "com.bluelionapps.intentexample";
public TygoIntentService(String name) {
super("TygoIntentService");
}
#Override
protected void onHandleIntent(Intent intent) {
//This is what the service does
Toast toast = Toast.makeText(getApplicationContext(), "Service Lauched", Toast.LENGTH_SHORT);
toast.show();
}
}
Here you see my complete Manifest but .TygoIntentService says TygoIntentService.java doesn't have a default constructor of my app. If i run it, it's just working but I want to know if this can give any problems in the future and if it gives one what i need to do.
Remove String name parameter from the constructor:
public TygoIntentService() {
super("TygoIntentService");
}
If you do not use/need the name String there, just remove the constructor, and let the compiler add it behind scenes by default.

Game not visible in the menu after .apk installation

I am facing a issue where my game becomes invisible in the menu after installation. Also when .apk installed, OPEN button becomes disabled and i'm unable to launch my game.
I made this game in Unity3D. I want to do deep-linking in my game so created my own Activity named as MainActivity extends UnityPlayerActivity and also did some changes in the AndroidManifest.xml file.
MainActivity.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public class MainActivity extends UnityPlayerActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d("MainActivity", "onCreate called!");
}
#Override
public void startActivity(Intent intent)
{
boolean isStartActivity = true;
Uri uri = intent.getData();
if (uri != null && uri.getScheme().equals("abc"))
{
isStartActivity = false;
}
if (isStartActivity)
{
super.startActivity(intent);
}
else
{
Log.d("MainActivity", "MainActivity.startActivity() : uri = " + uri.toString());
UnityPlayer.UnitySendMessage("Main Menu", "JuliusReward", uri.toString());
}
}
}
AndroidManifest.xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.xyz">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<!-- android:debuggable should be removed in release build -->
<application
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.abc.xyz.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "myapp://com.example.myapp” -->
<data android:scheme="abc" android:host="com.example.abc"/>
</intent-filter>
</activity>
<activity android:name="org.onepf.openiab.UnityProxyActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<receiver android:name="com.amazon.device.iap.ResponseReceiver">
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
</intent-filter>
</receiver>
</application>
<!--all-->
<uses-permission android:name="android.permission.INTERNET"/>
<!--Google Play-->
<uses-permission android:name="com.android.vending.BILLING" />
<!--For Tablets-->
<uses-feature android:name="android.hardware.telephony" android:required="false" />
</manifest>
Please check this post Intent filter for launcher and send activity
You should have an
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
and
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Emulator opens all activities when clicking just the above...?

here I am again.
I have a problem with my menu in combination with my activities.
When I run my emulator, and click the uppest item in the list, the emulator opens all list activities.
Hopefully someone can help me.. Thank you all in advance!
My Menu.Java:
package com.jacob.eindproject;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity implements OnItemClickListener {
String classes[] = { "BMI- Calculator", "Ondergewicht", "Gezond Gewicht", "Overgewicht"};
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//Positie 0 is het eerste item (dus de BMI-Calculator.)
super.onListItemClick(l, v, position, id);
switch(position)
{
case 0:
Intent openStartingPoint = new Intent(getApplicationContext(),MainActivity.class);
startActivity(openStartingPoint);
case 1:
Intent openOndergewicht = new Intent(getApplicationContext(),Ondergewicht.class);
startActivity(openOndergewicht);
case 2:
Intent openGezondgewicht = new Intent(getApplicationContext(),Gezond_gewicht.class);
startActivity(openGezondgewicht);
case 3:
Intent openOvergewicht = new Intent(getApplicationContext(),Overgewicht.class);
startActivity(openOvergewicht);
break;
}
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jacob.eindproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jacob.eindproject.Menu"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.jacob.eindproject.Inleiding"
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="com.jacob.eindproject.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Ondergewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.ONDERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Gezond_gewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.GEZOND_GEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Overgewicht"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.OVERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
First, there opens the Inleiding, it's my logo, and after 5 seconds it disappears.
After that, I want the menu with 4 items, 1 for the MainActivity.java, wich is a BMI-calculator. The last 3 items are informational items, about weight and stuff.
Somebody who knows the answer?
Thank you all for your efforts.
The reason all your activities open is because you don't have break statements at the end of each case clause in your switch. You need to add a break at the end of each case block.
Also, you should remove the <intent-filter> tags from all of your activities except the first one (Inleiding) that contains CATEGORY=DEFAULT and ACTION=MAIN. You don't need those and they will just confuse you.

Categories

Resources