Using a customer defined activity and i've declared the intent action in the manifest.xml
Here's the manifest file with the error
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.labs.dangerousapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<!--
TODO - Using a permission element,
define a custom permission with name
"course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
and "dangerous" protection level.
-->
<permission
android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
android:protectionLevel="dangerous"
>
</permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- TODO - enforce the custom permission on this Activity -->
<activity
android:permission="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
android:name=".DangerousActivity"
android:label="#string/app_name" >
<!--
TODO - add additional intent filter info so that this Activity
will respond to an Implicit Intent with the action
"course.labs.permissions.DANGEROUS_ACTIVITY"
-->
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
<action android:name="course.labs.permissions.DANGEROUS_ACTIVITY" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's where the intent was invoked in the program
Code:
package course.labs.permissionslab;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class GoToDangerousActivity extends Activity {
private static final String TAG = "Lab-Permissions";
private static final String DANGEROUS_ACTIVITY_ACTION = "course.labs.permissions.DANGEROUS_ACTIVITY";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.go_to_dangerous_activity);
Button startDangerousActivityButton = (Button) findViewById(R.id.start_dangerous_activity_button);
startDangerousActivityButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startDangerousActivity();
}
});
}
private void startDangerousActivity() {
Log.i(TAG, "Entered startDangerousActivity()");
startActivity(new Intent(DANGEROUS_ACTIVITY_ACTION));
}
}
Please let me know if any other info will hell, I've been tried everything i know and not sure why i'm getting this error again.
Did you installed the first App that has the manifest before calling using the second App?
[EDIT]
To check if a activity is registered to some Intent, you can use adb.exe available on Platform-tools folder to list all intents configured on the device.
To do that, on prompt execute the command below:
adb shell dumpsys package > packages.txt
Then open packages.txt and find for action name course.labs.permissions.DANGEROUS_ACTIVITY. Should have a activity associate with that action.
Try so:
startActivity(new Intent(getApplicationContext(), DANGEROUS_ACTIVITY_ACTION.class));
This is the normail way of doing it
[EDIT]
OR (note the different declaration of DANGEROUS_ACTIVITY_ACTION)
private static final String DANGEROUS_ACTIVITY_ACTION = ".DangerousActivity";
// ...
startActivity(new Intent(DANGEROUS_ACTIVITY_ACTION));
I use this in a SplashScreen Activity to call the Main Activity (after done loading my graphics from SVG files).
You need to run "DangerousApp" before running "GoToDangerousActivity".
This is because your dangerous app is not even installed on the device. If you were trying to do this from android studio, by default studio would try to launch the app which won't be successful because of the permission it needs. To install your dangerours, modify studio's launch settings to not to run the app right away. I got the same issue.
Related
My final goal is to easily activate and deactivate a certain series of 17 alarms in the clock app whenever necessary. Unfortunately, the app only offers the option to either deleting(!) all alarms at once or deactivating one by one. The same applies to every other app from the Play Store I have tried.
I think an acceptable workaround solution would be to delete all alarms with the mentioned functionality and re-implement the series of alarms programmatically as needed. So, I wrote a minimalist app in Android Studio that works perfectly fine in the emulator.
After building the debug APK, I transferred it on my smartphone and installed it without any errors. Now I am facing the problem that after starting my app only the first alarm is created. Does somebody have an explanation for this error. Thank you!
MainActivity.java
package com.example.setalarms;
import android.app.Activity;
import android.content.Intent;
import android.provider.AlarmClock;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] messages = {"alarm1","alarm2to16","alarm17"};
int[] hours = {7,8,9};
int[] minutes = {0,0,0};
ArrayList<Integer> days = new ArrayList<>(
Arrays.asList(1,2,3,4,5,6,7)
);
Intent[] intents = new Intent[messages.length];
for (int i = 0; i < messages.length; i++) {
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
.putExtra(AlarmClock.EXTRA_MESSAGE, messages[i])
.putExtra(AlarmClock.EXTRA_HOUR, hours[i])
.putExtra(AlarmClock.EXTRA_MINUTES, minutes[i])
.putExtra(AlarmClock.EXTRA_DAYS, days)
.putExtra(AlarmClock.EXTRA_SKIP_UI, i != messages.length - 1);
intents[i] = intent;
}
startActivities(intents);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.SetAlarms"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Hardware / Software
SAMSUNG Galaxy A3 (2017) SM-A320FL
Android Studio Dolphin 2021.3.1 Patch 1
Android 8.0.0 (Oreo)
Clock 7.0.92.7 (Galaxy Store)
total noob with lots of issues with Android Studio.
Default Activity error
Invalid java package name
Getting a Default Activity error on any app or new project I run - below is an example of the AndroidManifest.xml
"Error running 'app': Default Activity not found"
I have checked more than 100 times I am using the right package names and that my activity is declared in the android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.coleary.change;">
<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="com.example.coleary.change.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="#string/TicTacToe"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The package name is the same in the java code:
package com.example.coleary.change;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
// use tictactoe code in our code for a new game
private TicTacToeGame mGame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.example.coleary.change.R.layout.activity_main);
//this activity(game) is a context within a main activity
mGame= new TicTacToeGame(this);
}
}
When I run the project I get the following error also:
Package 'com.example.coleary.change;' from AndroidManifest.xml is not a valid Java package name as 'change;' is not a valid Java identifier.
I have changed the package name through Refactoring to 5 different names to no avail.
I have spent over 15 hours hours trying to troubleshoot these issues and because I have the same issue on multiple projects / packages and apps I am completely stuck - any help really appreciated!
Remove the semi-colon after change in your AndroidManifest. Package names can't contain semi-colons.
Hi all I have build a here map api for mobile but something wrong in device a map not show. I'll follow this tutorial Creating a Simple Application Using the HERE SDK but in Logcat not show any error i don't know what i wrong please see my code
Here Map Class:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.MapFragment;
public class hereMap extends AppCompatActivity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_here_map);
// Search for the map fragment to finish setup by calling init().
mapFragment = (MapFragment)getFragmentManager().findFragmentById(
R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error)
{
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center to the Vancouver region (no animation)
map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0),
Map.Animation.NONE);
// Set the zoom level to the average between min and max
map.setZoomLevel(
(map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment"+error.toString());
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_here_map, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here map Activity:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Map Fragment embedded with the map object -->
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="#+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mpat.bkklife" >
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".LoginActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize|stateVisible" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="My App ID:************"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="My App Token:***********"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="My License Key:***********"/>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
</activity>
<activity
android:name=".hereMap"
android:label="#string/title_activity_here_map" >
</activity>
</application>
</manifest>
UPDATE
I got a error in log cat it say "ERROR: Cannot initialize Map Fragment MISSING_LIBRARY" when my app is init the map. But i already include HERE SDK and armeabi-v7a.
SpecDevice: Galaxsy S4 android 5.0.1 Lollipop
and this is my lib in project:
What i wrong of my code? Thank every one.
Try changing this line:
System.out.println("ERROR: Cannot initialize Map Fragment");
to this:
System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString());
then check the log to see what OnEngineInitListener.Error you are receiving. This will help you find the root cause of the issue.
As Shiv mentioned in the comments, based on the AndroidManifest you posted it looks like the culprit could be a missing appId appCode and/or license key.
As a side note, instead of System.out.println, you should really use android.util.Log
Also, did you fill in the following lines in the manifest file:
<meta-data android:name="com.here.android.maps.appid" android:value="My App ID"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="My App Token"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="My License Key"/>
Please insert the appid, token and evaluation key that you obtained when registering the application.
Also, did you copy the native libraries from the SDK package ?
The structure should be:
"project root"\libs\armeabi-v7a*.so
It looks like the SDK package only includes native libraries for armeabi, so when you try to run on a device with a different CPU architecture (see https://developer.android.com/ndk/guides/abis.html), it can't find the proper binaries.
I'd be curious if you found a work-around, because this prevents my app from working on any device with a non armeabi CPU.
Please check which NAME SPACE you add with your application
Important: You must use the same package name as you have registered on developer.here.com. Failure to do so leads to a blank map to appear in your application.
some time we create application in short time so its might be possible to we miss few steps .
and if we are working on more then one apps its happens :)
I know it'a already many questions was like this, I read all of them, and can't find solution anyway. What i did:
I did all this steps fine from http://developer.android.com/google/play-services/setup.html#Install to install google play sdk
In my project property in Android tab I have "google play service library" ok, in Java Builder Path: "Android Private Libraries" i have google-play-service.jar, and this library are selected. I did Import lib project also.
Code for testing i took from http://developer.android.com/google/gcm/client.html.
My manifest file:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.intent.RECEIVE" />
<permission
android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key here" />
<receiver
android:name="lt.vaziouju.vaziuoju.GcmBroadcastReceiver"
android:permission="lt.vaziouju.vaziuoju.c2dm.permission.SEND" >
<intent-filter>
<action android:name="lt.vaziouju.vaziuoju.c2dm.intent.RECEIVE" />
<category android:name="lt.vaziouju.vaziuoju" />
</intent-filter>
</receiver>
<service android:name="lt.vaziouju.vaziuoju.GcmIntentService" />
<activity
...
</activity>
</application>
My java code:
package lt.vaziouju.vaziuoju;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class Test_GCM extends Activity {
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private static final String TAG = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test__gcm);
TextView mDisplay = (TextView) findViewById(R.id.display);
Context context = getApplicationContext();
// Check device for Play Services APK.
if (checkPlayServices()) {
// If this check succeeds, proceed with normal processing.
// Otherwise, prompt user to get valid Play Services APK.
}
}
// You need to do the Play Services APK check here too.
#Override
protected void onResume() {
super.onResume();
checkPlayServices();
}
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test__gcm, menu);
return true;
}
}
If you have any idea how I can it, it will be grate. I know I'm not good enough in android programming, and just started learning GCM but I'm already spend 6h to reading a google, and nothing.
Thanks for any idea.
Are you using Eclipse? If Eclipse sees a jar file for compilation, it does not necessarily include it into the apk. (You have to mention the jar in several places, and usually people do not remember in how many places.)
ritht-click on the project name -- build path -- configure build path -- order and export.
The same dialog has a Projects tab, this is where you specify projects you depend on.
If that does not work, put the jar into the libs subdirectory of your project.
I know this has been asked ALOT on here, but I have been scouring the interwebs for hours and I have even reused some of my previous code for receiving sms' and I got...nothing.
So, here goes, basic app to receive SMS but the app never receives the intent. I thought the intent may be ignored if the text is sent from the same phone but that does not seem to be the case, as other apps pick up the text fine.
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.encima.smsreceiver"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<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=".MessageReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>
And, here is the receiver, nothing seems to be new here, so I have no idea what the problem is:
package com.encima.smsreceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class MessageReceiver extends BroadcastReceiver {
private static final String TAG = "Message recieved";
#Override
public void onReceive(Context context, Intent intent) {
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) pudsBundle.get("pdus");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);
Log.i(TAG, messages.getMessageBody());
Toast.makeText(context, "SMS Received : "+messages.getMessageBody(),
Toast.LENGTH_LONG).show();
}
}
The debug phone I am using is running 2.2.2 and I have other apps running that detect sms, including some of my own.
Any insight into this would be appreciated!
Thanks
Because the SMS broadcast intent is sent by
Context.sendOrderedBroadcast(...),
if any other app registers the BroadcastReceiver and calls abortBroadcast, the other receiver will not get the broadcast.
To increase the probability of your app receiving the broadcast create an IntentFilter, use IntentFilter.setPriority.
I do not know if this is your problem but you should definitelly try this:
Instead of ".MessageReceiver" put android:name = "com.encima.smsreceiver.MessageReceiver"
This is fix that workout many times for me when something doesn't get called.