1
㈡有一個代碼,以從其他應用程序,代碼工作以及打開計算器,但我更改包名來打開不同的應用程序無法正常工作機器人工作室不容打開其他應用
有誰知道我不得不改變
package com.example.zeluis.c4;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class c4 extends AppCompatActivity {
// aki comesa abrir os app
private String packge_name = "com.android.calculator2";
private String class_name = "com.android.calculator2.Calculator";
private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c4);
bt = (Button) findViewById(R.id.but);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
launchCall();
}
});
}
protected void launchCall() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packge_name, class_name));
try {
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
@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_c4, 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);
}
}
我的想法是更改包名稱來打開另一個應用程序,如whatapp或Navfree .etc
我不確定確切的問題是什麼,你是說'launchCall()'不工作?如果是這樣,請展示它的功能。 –
你已經提供了一切,但我們實際需要看到的代碼位... –
現在我過去了所有的代碼。此代碼工作,但我想打開其他應用程序不是計算器我不能 –