I'm having issues getting an sms text to send. When I click the button, nothing happens. No message or anything.
What doesn't make sense is that it works as a standalone app for sms sending, but if I integrate the code into my larger project, it doesn't send the sms. Nothing happens.
Something has to conflicting with Smsmanager or something. Can anyone give me advice on why it doesn't work anymore?
Android Manifest
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android_auto">
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name"
android:supportsRtl="true" android:theme="#style/AppTheme">
<activity android:name=".engine.MainActivity" android:label="#string/app_name" android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.MapsActivity1">
</activity>
<meta-data android:name="com.google.android.gms.car.application" android:resource="#xml/automotive_app_desc" />
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCMFYfJ6aOuxJk3W0vmhF6Nou3TP_qIU6c" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!--
Main music service, provides media browsing and media playback services to
consumers through MediaBrowserService and MediaSession. Consumers connect to it through
MediaBrowser (for browsing) and MediaController (for playback control)
-->
<service android:name=".MyMusicService" android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<service android:name=".MyMessagingService" />
<receiver android:name=".MessageReadReceiver">
<intent-filter>
<action android:name="com.example.zachboone.myapplication.ACTION_MESSAGE_READ" />
</intent-filter>
</receiver>
<receiver android:name=".MessageReplyReceiver">
<intent-filter>
<action android:name="com.example.zachboone.myapplication.ACTION_MESSAGE_REPLY" />
</intent-filter>
</receiver>
</application>
</manifest>
SendSmsActivity.java
package android_auto.engine;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android_auto.R;
public class SendSmsActivity extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
buttonSend = (Button) findViewById(R.id.buttonSend);
textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
textSMS = (EditText) findViewById(R.id.editTextSMS);
buttonSend.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
PendingIntent pendingIntent = PendingIntent.getBroadcast(SendSmsActivity.this, 0, new Intent("SMS_SENT"), 0);
smsManager.sendTextMessage(phoneNo, null, sms, pendingIntent, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
activity_sms.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewPhoneNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Phone Number : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editTextPhoneNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:phoneNumber="true" >
</EditText>
<TextView
android:id="#+id/textViewSMS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter SMS Message : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editTextSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="5"
android:gravity="top" />
<Button
android:id="#+id/buttonSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
Try editing your code in click listener to this
PendingIntent pendingIntent = PendingIntent.getBroadcast(SendSmsActivity.this, 0,new Intent("SMS_SENT"), 0);
smsManager.sendTextMessage(phoneNo, null, sms, pendingIntent, null);
Hope this helps you making it working.
Related
My AndroidManifest file is showing an error "Unresolved class 'MainActivity' ", but i have a java class and file by that name in the package and it is supposed to be the first activity of the program so when i try to run the program it crashes up , i've checked my code but couldn't find any problem there .
java code for MainActivity file
package com.example.tictactoe;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button forward;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
forward = (Button)findViewById(R.id.start);
forward.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(MainActivity.this,GameUi.class));
}
});
}
#Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setMessage("Do you want to Exit?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton("No",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
}
}
java code for second activity which my program uses ("GameUi.java")
package com.example.tictactoe
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
public class GameUi extends AppCompatActivity {
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_ui);
btn=(Button)findViewById(R.id.backbtn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(GameUi.this, MainActivity.class));
}
});
}
}
AndroidManifest file code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tictactoe">
<application
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/Theme.TicTacToe">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity xml file code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E5E6AD"
tools:context=".MainActivity">
<TextView
android:id="#+id/Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_marginBottom="332dp"
android:editable="false"
android:text="Hello Aliens!"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="50dp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="#+id/Alienimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/Heading"
app:srcCompat="#drawable/ic_launcher_foreground" />
<Button
android:id="#+id/Startbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000066"
android:letterSpacing="0.5"
android:padding="0dp"
android:text="Start"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Alienimg"
app:layout_constraintVertical_bias="0.886" />
</androidx.constraintlayout.widget.ConstraintLayout>
In your class's I don't see the package at top.
Try adding it and see, if you still face the issue, try invalidate and restarting.
package com.example.tictactoe;
This is the cause of error
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the intent-filter is used to define that which activity will be your first activity ( when you start your Android Application ). You can use it in both activities so the App will confuse which is your first Activity so they give error.
In case MainActivity is your first activity
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
</activity>
Your manifest is Ok ( I guess you fixed the intent-filter issue based on
Abdullah Sheikh answer). the problem is because of this line in MainActivity :
forward = (Button)findViewById(R.id.start);
because your button id is Startbtn not start
just replace that with :
forward = (Button)findViewById(R.id.Startbtn);
also in activity_main and ImageView remove
app:srcCompat="#drawable/ic_launcher_foreground"
or find another src for drawable.
Im trying to develop a flashlight app as my first "real" app, and almost everything worked. But everytime I want to turn my flashlight off, my app just crashes. Code and Logcat log follows:
package com.leuchtstein.flashlight;
import android.hardware.Camera;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public boolean stat = false;
TextView text;
Camera camera;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.textView);
}
public void triggerlight(View view) {
if (stat == false) {
camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
text.setText("ON");
stat = true;
} else {
camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.stopPreview();
camera.release();
text.setText("OFF");
stat = false;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.leuchtstein.flashlight.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/desc_textview"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="triggerlight"
android:text="Turn on/off"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:layout_constraintVertical_bias="0.387" />
</android.support.constraint.ConstraintLayout>
Logcat:
https://pastebin.com/tNyF6GvX
Thanks in advance, leuchtstein.
EDIT: Yes, I have the uses-permission function:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.leuchtstein.flashlight">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<application
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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Use the following permission in
AndroidManifest.xml
file
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
And follow this thread for more information
fail-to-connect-to-camera-service
In main2.xml there are apparently no errors. Same thing for main.xml however I think the problem lies here somewhere.
Quick Summary of what the app is: It is meant to use Google Maps onClick of a button but I am getting errors so I can just load the main menu on testing.
XML
I don't have enough rep to post picture so error pic can be found here
main2.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Club Deals"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GPS locations" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Closest Deals"
android:onClick="open_close_deals" />
<Button
android:id="#+id/button6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cheapest Deals"
android:onClick="open_cheap_deals" />
<Button
android:id="#+id/button7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Best Value Deals"
android:onClick="best_value" />
<Button
android:id="#+id/button8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Best Events"
android:onClick="best_events" />
<Button
android:id="#+id/button9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="News"
android:onClick="news"/>
</LinearLayout>
AppActivity.java
In AppActivity I am given
"map cannot be resolved or is not a field" & "main2 cannot be resolved or is not a field"
package com.example.clubnightsdeals;
import android.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class AppActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
}
});
};
public void addListenerOnButtonNews() {
final Context context = this;
button = (Button) findViewById(R.id.button9);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
}
});
};
/* protected void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
*/
// Google Map
GoogleMap googleMap;
protected void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
In App2Activity I am given the error "The import com.example.clubnightsdeals.R cannot be resolved"
App2Activity.java
package com.example.clubnightsdeals;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import com.example.clubnightsdeals.R;
public class App2Activity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clubnightsdeals"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/clubnightsdeals"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library
android:name="com.google.android.maps" />
<activity
android:label="#string/clubnightsdeals"
android:name=".App2Activity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDetfYqNFORnvtR245fht3RIK25T6DRY" />
<activity
android:name="info.androidhive.googlemapsv2.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You are pointing to wrong R.java file. Replace your following import line
import android.R;
with
import com.example.clubnightsdeals.R;
in your AppActivity.java file.
Your error shows that you have not closed the <activity> tag in your manifest file.
Make sure you have closed your activity tag as <activity android:name=""...../> or <activity android:name=""> </activity>
First remove
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
in manifest (cannot have 2 start activity in a App) then try to import R library.
If it still has this R error, check your xml files - make sure check all xml files.
I am developing a game in libgdx. I read the official docs and tried to integrate MobClix Ads in my App but eclipse can't resolve this constructor for ADView class: (for Example):
AdView ad = new AdView(this, AdSize.BANNER, "a14d91b10f12454");
This line of code give me an error.
Maybe my import is not correct? I import this:
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
And the same for:
adView.loadAd(new AdRequest());
I tried to search for an answer but I coudn't find, Does somone know how to resolve this?
Sorry for my poor english.
Put this code to mainactivity
import android.app.Activity;
import android.os.Bundle;
import com.startapp.android.publish.StartAppAd;
public class MainActivity extends Activity {
private StartAppAd add = new StartAppAd(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StartAppAd.init(this, "105158220", "205151606");
//StartAppSearch.init(this, "105158220", "205151606");
setContentView(R.layout.activity_main);
if(add.isReady())
{
add.showAd(); // show the ad
add.loadAd();
}
//a.loadAd(AdMode.FULLPAGE);
}
#Override
public void onResume(){
super.onResume();
add.onResume();
}
#Override
public void onBackPressed() {
add.onBackPressed();
super.onBackPressed();
}
#Override
public void onPause() {
super.onPause();
add.onPause();
}
}
put this into your xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.startapp.android.publish.banner.banner3d.Banner3D
android:id="#+id/startApp3DBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
put this into ur Manifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.start_up_app.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
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.startapp.android.publish.list3d.List3DActivity"
android:taskAffinity="com.example.start_up_app.AppWall"
android:theme="#android:style/Theme" />
<activity
android:name="com.startapp.android.publish.AppWallActivity"
android:configChanges="orientation|keyboardHidden"
android:taskAffinity="com.example.start_up_app.AppWall"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>
for you have to use StartAppCommon-1.0.1.jar and StartAppInApp-2.0.7.jar
I have been messing around with this for a few days now and have the code identical to that in the tutorial and yet it still doesn't want to work, Why?
MainActivity.java
package com.example.mdpmk1;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.scan);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, ScanScreen.class);
startActivity(intent);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Screen One......"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/scan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click me to another screen" />
</LinearLayout>
ScanScreen.java
package com.example.mdpmk1;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class ScanScreen extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scan_screen);
}
}
scan_screen.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You have done it!!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapp"
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.example.firstapp.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>
Any help would be lovely, This has relay been annoying me and i know that it is probably a simple mistake.
Add the following in your AndroidManifest.xml
<activity android:name=".ScanScreen" />
within application like so:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapp.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=".ScanScreen" />
</application>
Here is a quote from the official docs on what the activity tags are for:
Declares an activity (an Activity subclass) that implements part of
the application's visual user interface. All activities must be
represented by elements in the manifest file. Any that are
not declared there will not be seen by the system and will never be
run.
That last sentence is important.
In your case writing <activity android:name=".ScanScreen" /> above </application> will solve your problem.
Whenever you need to use any activity in android you have to mention it in AndroidManifest.xml file. Just giving answer to you won't help you.
You should first read on below links to understand what is intent and intent-filters used for.
http://developer.android.com/reference/android/content/Intent.html
http://developer.android.com/guide/components/intents-filters.html
What is an Intent in Android?
Your app crashes because your not setting or registered the activity in manifest.You haven't added the ScanScreen Activity in your manifest file.
Just add the following to your AndroidManifest.xml :
<activity android:name=".ScanScreen" />
within your application tag like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapp.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=".ScanScreen" />
</application>