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>
Related
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" />
Im trying to make an application with Google Cloud Messaging and i followd all the exact steps for implementing GCMclient on developer page, code just seems to crash on launch. Is there any fault in activity main? or some logical flaw of how android sets up its application on creation? im new to android programming.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotproj.clandestine"
android:versionCode="1"
android:versionName="1.0" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.iotproj.clandestine.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="GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.iotproj.clandestine" />
</intent-filter>
</receiver>
<service android:name="GcmIntentService" />
</application>
</manifest>
public class MainActivity extends Activity {
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;TextView mDisplay;
Button mButton;
GoogleCloudMessaging gcm;
Context appContext = getApplicationContext();
// this is quite important dude
String registrationId = null;
String SENDER_ID = "xxxxxxxxx";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDisplay = (TextView) findViewById(R.id.pool);
mButton = (Button) findViewById(R.id.getid);
// Check device for Play Services APK.
if (!checkPlayServices()) {
mDisplay.setText("device not supproted !"); button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
gcm = GoogleCloudMessaging.getInstance(appContext);
try{
registrationId = gcm.register(SENDER_ID);
}
catch(IOException e){
mDisplay.setText(e.getMessage());
}
}
});
}`
Register your broadcast receiver like this way.
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.iotproj.clandestine" />
</intent-filter>
</receiver>
for Service
<service android:name=".GCMIntentService" />
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.
As I understood, if I define configuration activity for widget, onUpdate() method will not call, until I'll not configure it. But in my case, and I wonder why - configuration activity doesn't start, and update method calls after placing widget. My application have other activities, one of them starts when application run, maybe that's is the reason? Here my code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.watcom.MobileInformer"
android:versionCode="2"
android:versionName="1.01"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<application android:label="#string/app_name" android:theme="#style/WatcomTheme" android:icon="#drawable/icon">
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="false"/>
<activity android:name=".AuthorizationActivity"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
</intent-filter>
</activity>
<activity android:launchMode="singleTop" android:name=".WidgetConfigureActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity android:name=".ProjectsActivity" android:screenOrientation="portrait"/>
<receiver
android:icon="#drawable/icon"
android:label="Watcom informer"
android:name=".MyWidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="ru.example.android.widget.ACTION_WIDGET_RECEIVER"/>
</intent-filter>
<intent-filter>
<action android:name="com.watcom.MobileInformer.UPDATE_WIDGET"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
</receiver>
</application>
<uses-permission xmlns:android="http://schemas.android.com/apk/res/android"
android:name="android.permission.INTERNET" />
</manifest>
widget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="schemas.android.com/apk/res/android"
android:minHeight="320dp"
android:minWidth="100dp"
android:updatePeriodMillis="1800000"
android:initialLayout="#layout/widget_layout"
android:configuration="com.watcom.MobileInformer.WidgetConfigureActivity"/>
WidgetConfigureActivity
public class WidgetConfigureActivity extends Activity {
int widgetId;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
setContentView(R.layout.login_layout);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras!=null)
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
if (widgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
setResult(RESULT_OK, resultValue);
finish();
}
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" />